foldkit-cms-drizzle 0.1.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["text","integer","pgText","pgInteger"],"sources":["../src/tables.ts","../src/index.ts"],"sourcesContent":["/**\n * The three tables the CMS keeps beside the application's own. Drizzle tables\n * are made per dialect, so there is one definition for each; they have the same\n * columns. An application adds them to its schema and its migrations as it does\n * any table, and may define its own instead, so long as the columns are these.\n */\nimport { integer as pgInteger, jsonb, pgTable, text as pgText } from 'drizzle-orm/pg-core'\nimport { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'\n\n/**\n * - `cms_entries`: a piece of content from first keystroke to archive. It exists\n * before its content row does.\n * - `cms_drafts`: an entry's one working copy; its id is the entry's.\n * - `cms_revisions`: published values, append-only.\n */\nexport const sqliteTables = () => ({\n entries: sqliteTable('cms_entries', {\n id: text('id').primaryKey(),\n type: text('type').notNull(),\n targetId: text('target_id'),\n label: text('label').notNull(),\n createdBy: text('created_by'),\n createdAt: text('created_at').notNull(),\n archivedAt: text('archived_at'),\n revision: integer('revision'),\n }),\n drafts: sqliteTable('cms_drafts', {\n id: text('id').primaryKey(),\n values: text('values', { mode: 'json' }),\n model: text('model', { mode: 'json' }),\n form: text('form').notNull(),\n updatedAt: text('updated_at').notNull(),\n updatedBy: text('updated_by'),\n baseRevision: integer('base_revision'),\n scheduledFor: text('scheduled_for'),\n scheduledBy: text('scheduled_by'),\n scheduleError: text('schedule_error'),\n }),\n revisions: sqliteTable('cms_revisions', {\n id: text('id').primaryKey(),\n entryId: text('entry_id').notNull(),\n n: integer('n').notNull(),\n values: text('values', { mode: 'json' }),\n publishedAt: text('published_at').notNull(),\n publishedBy: text('published_by'),\n }),\n})\n\nexport const pgTables = () => ({\n entries: pgTable('cms_entries', {\n id: pgText('id').primaryKey(),\n type: pgText('type').notNull(),\n targetId: pgText('target_id'),\n label: pgText('label').notNull(),\n createdBy: pgText('created_by'),\n createdAt: pgText('created_at').notNull(),\n archivedAt: pgText('archived_at'),\n revision: pgInteger('revision'),\n }),\n drafts: pgTable('cms_drafts', {\n id: pgText('id').primaryKey(),\n values: jsonb('values'),\n model: jsonb('model'),\n form: pgText('form').notNull(),\n updatedAt: pgText('updated_at').notNull(),\n updatedBy: pgText('updated_by'),\n baseRevision: pgInteger('base_revision'),\n scheduledFor: pgText('scheduled_for'),\n scheduledBy: pgText('scheduled_by'),\n scheduleError: pgText('schedule_error'),\n }),\n revisions: pgTable('cms_revisions', {\n id: pgText('id').primaryKey(),\n entryId: pgText('entry_id').notNull(),\n n: pgInteger('n').notNull(),\n values: jsonb('values'),\n publishedAt: pgText('published_at').notNull(),\n publishedBy: pgText('published_by'),\n }),\n})\n\n/** The `create table` statements for SQLite, for a test or a first migration. */\nexport const sqliteSchema = `\ncreate table if not exists cms_entries (\n id text primary key, type text not null, target_id text, label text not null,\n created_by text, created_at text not null, archived_at text, revision integer\n);\ncreate table if not exists cms_drafts (\n id text primary key, \"values\" text, model text, form text not null,\n updated_at text not null, updated_by text, base_revision integer,\n scheduled_for text, scheduled_by text, schedule_error text\n);\ncreate table if not exists cms_revisions (\n id text primary key, entry_id text not null, n integer not null, \"values\" text,\n published_at text not null, published_by text\n);\n`\n\nexport type CmsTables = ReturnType<typeof sqliteTables> | ReturnType<typeof pgTables>\n","/**\n * `foldkit-cms-drizzle` — the server half of `foldkit-cms`.\n *\n * It keeps an author's unpublished work in three tables beside the\n * application's own, and it is where the audience boundary is enforced: a\n * principal that is not an author is refused entries, drafts and revisions\n * outright, and sees of the content only the rows its `published` role shows.\n * Both are a binding's `visible`, so they hold on every path a table is read by.\n *\n * Publishing runs the application's own mutation with the draft's value, inside\n * a transaction that also appends the revision and removes the draft, so a\n * publish happened entirely or did not happen.\n */\nimport {\n and,\n eq,\n inArray,\n isNotNull,\n isNull,\n lte,\n ne,\n sql,\n type AnyColumn,\n type SQL,\n} from 'drizzle-orm'\nimport { Effect, Exit, Schema, Semaphore } from 'effect'\nimport { Cms, type Content, type Facts } from 'foldkit-cms'\nimport type { MutationDescriptor } from 'foldkit-remote'\nimport {\n DrizzleDatabase,\n bind,\n query,\n returning,\n source,\n type AnyEntityBinding,\n type DrizzleDatabaseService,\n type Visible,\n} from 'foldkit-remote-drizzle'\nimport {\n RemoteServer,\n RemoteServerError,\n type EntitySource,\n type MutationOutcome,\n type MutationSource,\n type QuerySource,\n} from 'foldkit-remote-server'\nimport type { CmsTables } from './tables.js'\n\nexport { pgTables, sqliteSchema, sqliteTables, type CmsTables } from './tables.js'\n\n/** The writes the CMS makes, as any Drizzle database for SQLite or Postgres offers them. */\ninterface Writes {\n insert(table: unknown): { values(values: object): PromiseLike<unknown> }\n update(table: unknown): {\n set(values: object): {\n where(condition: SQL | undefined): {\n returning(columns: Record<string, AnyColumn>): PromiseLike<ReadonlyArray<object>>\n }\n }\n }\n delete(table: unknown): { where(condition: SQL | undefined): PromiseLike<unknown> }\n}\n\n/**\n * A content type as the server holds it: its declaration, the binding of its\n * table, and the application's own handlers of its two publish mutations. What\n * publishing a post does stays the application's code.\n */\nexport interface ServedContent<P = any> {\n readonly type: Content<string, any, any, any>\n readonly binding: AnyEntityBinding\n readonly create: MutationSource<P, DrizzleDatabase>\n readonly update: MutationSource<P, DrizzleDatabase>\n}\n\n/** What an author may be refused, by `allow`. */\nexport type Asked =\n | 'save'\n | 'discard'\n | 'publish'\n | 'unpublish'\n | 'schedule'\n | 'unschedule'\n | 'archive'\n | 'unarchive'\n | 'restore'\n\n/**\n * Runs some work so that it happened entirely or did not. Drizzle's own\n * transactions differ by driver, so the application says which this is.\n */\nexport type Transaction = <A, E>(\n work: Effect.Effect<A, E, DrizzleDatabase>,\n) => Effect.Effect<A, E, DrizzleDatabase>\n\nconst statement = (database: DrizzleDatabaseService, text: string) =>\n Effect.promise(() => {\n const runs = database as unknown as {\n run?: (query: SQL) => unknown\n execute?: (query: SQL) => unknown\n }\n return Promise.resolve(\n runs.run !== undefined ? runs.run(sql.raw(text)) : runs.execute!(sql.raw(text)),\n )\n })\n\n// One connection holds one transaction. Without this, a write another request\n// makes between this one's `begin` and its `rollback` is rolled back with it,\n// after it was reported done.\nconst turns = new WeakMap<object, Semaphore.Semaphore>()\nconst turnOf = (database: object): Semaphore.Semaphore => {\n const held = turns.get(database)\n if (held !== undefined) return held\n const made = Semaphore.makeUnsafe(1)\n turns.set(database, made)\n return made\n}\n\nexport const Transaction = {\n /**\n * `begin`, the work, then `commit` or `rollback`, as statements. For a database\n * that is one connection, such as a SQLite file, which it takes turns at: the\n * operations of this package wait for one another. A write of your own on the\n * same connection does not, so make it inside `Transaction.statements` too.\n * Over a pool each statement may take a different connection: use `drizzle` there.\n */\n statements: (<A, E>(work: Effect.Effect<A, E, DrizzleDatabase>) =>\n Effect.gen(function* () {\n const database = yield* DrizzleDatabase\n return yield* turnOf(database).withPermit(\n statement(database, 'begin').pipe(\n Effect.andThen(work),\n Effect.onExit(exit => statement(database, Exit.isSuccess(exit) ? 'commit' : 'rollback')),\n ),\n )\n })) as Transaction,\n /**\n * Drizzle's `database.transaction`, with the work given the transaction as its\n * database. For a driver whose transactions are asynchronous: Postgres, libSQL.\n */\n drizzle: (<A, E>(work: Effect.Effect<A, E, DrizzleDatabase>) =>\n Effect.gen(function* () {\n const database = (yield* DrizzleDatabase) as unknown as {\n transaction: <T>(run: (inner: DrizzleDatabaseService) => Promise<T>) => Promise<T>\n }\n const failed = Symbol('failed')\n let exit: Exit.Exit<A, E> | undefined\n // A failure must leave the callback as a rejection, or Drizzle commits.\n yield* Effect.promise(() =>\n database\n .transaction(async inner => {\n exit = await Effect.runPromiseExit(\n work.pipe(Effect.provideService(DrizzleDatabase, inner)),\n )\n if (!Exit.isSuccess(exit)) throw failed\n })\n .catch(error => {\n if (error !== failed) throw error\n }),\n )\n return yield* exit!\n })) as Transaction,\n}\n\nexport interface CmsServerConfig<P> {\n readonly tables: CmsTables\n readonly content: ReadonlyArray<ServedContent<P>>\n /** How a publish is made whole: `Transaction.statements` or `Transaction.drizzle`. */\n readonly transaction: Transaction\n /** Who reads and writes unpublished work. Everyone else is a visitor. */\n readonly isAuthor: (principal: P) => boolean\n /**\n * Whether this author may make this transition. It is asked after the entry is\n * found and the transition is one its state offers. Default: any author may.\n */\n readonly allow?: (principal: P, transition: Asked, entry: EntryRow) => boolean\n /** The server's clock, passed in so a test can hold it. */\n readonly now?: () => Date\n /**\n * The most a draft may hold, as the characters of its JSON: its values and its\n * form's Model together. An author is trusted with their own content, not with\n * the database's disk. Default: one million.\n */\n readonly maxDraftSize?: number\n /** Who a principal is, for `createdBy` and `updatedBy`. */\n readonly nameOf?: (principal: P) => string | null\n}\n\n/** A row of `cms_entries`, as the server's rules see it. */\nexport interface EntryRow {\n readonly id: string\n readonly type: string\n readonly targetId: string | null\n readonly label: string\n readonly archivedAt: string | null\n readonly revision: number | null\n}\n\nconst refuse = (message: string) => new RemoteServerError({ message })\n\n/**\n * Whether a unique index on this column refused a write. Drivers say so in their\n * own words, and Drizzle wraps what they say, so every message down the chain of\n * causes is read. SQLite names the column; Postgres names the constraint, which\n * by default is made of the column's name.\n */\nconst refusedAsDuplicate = (defect: unknown, column: string): boolean => {\n const said: Array<string> = []\n for (let at = defect, depth = 0; at != null && depth < 5; depth++) {\n const { message, constraint, cause } = at as {\n readonly message?: unknown\n readonly constraint?: unknown\n readonly cause?: unknown\n }\n // Drizzle's own message quotes the statement, which names every column.\n if (!String(message).startsWith('Failed query'))\n said.push(String(message ?? at), String(constraint ?? ''))\n at = cause\n }\n const text = said.join(' ')\n const named = new RegExp(`(^|[^a-zA-Z0-9])${column.replace(/[^\\w]/g, '.')}([^a-zA-Z0-9]|$)`)\n return /unique|duplicate/i.test(text) && named.test(text)\n}\n\n/**\n * For a content table's binding: a visitor sees the rows whose `published`\n * column is set, and an author sees every row. Give it as the storage's\n * `visible` when the table is bound; `CmsServer.make` refuses a content type\n * that can be unpublished and whose binding shows every row to everyone.\n */\nexport const published =\n <P>(column: AnyColumn, isAuthor: (principal: P) => boolean): Visible =>\n principal =>\n isAuthor(principal as P) ? undefined : isNotNull(column)\n\nexport const CmsServer = {\n make: <P = unknown>(config: CmsServerConfig<P>) => {\n const { tables, isAuthor } = config\n const now = config.now ?? (() => new Date())\n const nameOf = config.nameOf ?? (() => null)\n const maxDraftSize = config.maxDraftSize ?? 1_000_000\n\n const byType = new Map(config.content.map(served => [served.type.name, served]))\n for (const { type, binding, create, update } of config.content) {\n for (const [handler, declared] of [\n [create, type.publish.create],\n [update, type.publish.update],\n ] as const)\n if (handler.mutation !== declared.name)\n throw new Error(\n `foldkit-cms-drizzle: content \"${type.name}\" publishes through \"${declared.name}\", but was given the handler of \"${handler.mutation}\"`,\n )\n if (type.roles.published === undefined) continue\n // Whether the rule is right is the application's to say: only it knows what a\n // principal is. That there is one at all is checked here.\n if (binding.visible === undefined)\n throw new Error(\n `foldkit-cms-drizzle: content \"${type.name}\" can be unpublished, but its binding shows every row to everyone; bind its table with \\`visible: published(column, isAuthor)\\``,\n )\n }\n\n // Unpublished work is an author's. To anyone else these tables are empty, on\n // every path they are read by.\n const authorsOnly: Visible = principal => (isAuthor(principal as P) ? undefined : sql`0 = 1`)\n const Db = bind(Cms.Entities, {\n Entry: {\n table: tables.entries,\n visible: authorsOnly,\n relations: {\n draft: { foreignKey: tables.drafts.id },\n revisions: {\n foreignKey: tables.revisions.entryId,\n orderBy: [{ column: tables.revisions.n, direction: 'desc' }],\n },\n },\n // Not a column: this server derives it, below, with its own clock.\n derived: { state: { supplied: true } },\n },\n Draft: { table: tables.drafts, visible: authorsOnly },\n Revision: { table: tables.revisions, visible: authorsOnly },\n })\n\n /** What is known of some entries, for their state: their drafts, and whether a visitor sees their rows. */\n const factsOf = (entries: ReadonlyArray<EntryRow>) =>\n Effect.gen(function* () {\n const database = yield* DrizzleDatabase\n const ids = entries.map(entry => entry.id)\n const drafts =\n ids.length === 0\n ? []\n : yield* Effect.promise(() =>\n Promise.resolve(\n database\n .select({\n id: tables.drafts.id,\n scheduledFor: tables.drafts.scheduledFor,\n scheduleError: tables.drafts.scheduleError,\n })\n .from(tables.drafts)\n .where(inArray(tables.drafts.id, ids)),\n ),\n )\n const draftOf = new Map(drafts.map(draft => [String(draft.id), draft]))\n\n // Per content type, which target rows exist and which a visitor would see.\n const rows = new Map<string, 'visible' | 'hidden'>()\n for (const [name, { type, binding }] of byType) {\n const targets = entries.flatMap(entry =>\n entry.type === name && entry.targetId !== null ? [entry.targetId] : [],\n )\n if (targets.length === 0) continue\n const id = binding.columns.id!\n const publishedColumn =\n type.roles.published === undefined\n ? undefined\n : binding.columns[type.roles.published.key]\n const found = yield* Effect.promise(() =>\n Promise.resolve(\n database\n .select({\n id,\n ...(publishedColumn === undefined ? {} : { shown: publishedColumn }),\n })\n .from(binding.table)\n .where(inArray(id, targets)),\n ),\n )\n for (const row of found)\n rows.set(\n `${name}:${String(row.id)}`,\n publishedColumn === undefined || row.shown !== null ? 'visible' : 'hidden',\n )\n }\n\n return new Map(\n entries.map((entry): readonly [string, Facts] => {\n const draft = draftOf.get(entry.id)\n return [\n entry.id,\n {\n archivedAt: entry.archivedAt,\n row:\n entry.targetId === null\n ? 'none'\n : (rows.get(`${entry.type}:${entry.targetId}`) ?? 'none'),\n draft:\n draft === undefined\n ? null\n : {\n scheduledFor: (draft.scheduledFor as string | null) ?? null,\n scheduleError: (draft.scheduleError as string | null) ?? null,\n },\n },\n ]\n }),\n )\n })\n\n const entryColumns = {\n id: tables.entries.id,\n type: tables.entries.type,\n targetId: tables.entries.targetId,\n label: tables.entries.label,\n archivedAt: tables.entries.archivedAt,\n revision: tables.entries.revision,\n }\n const findEntry = (id: string) =>\n Effect.gen(function* () {\n const database = yield* DrizzleDatabase\n const [row] = yield* Effect.promise(() =>\n Promise.resolve(\n database\n .select(entryColumns)\n .from(tables.entries)\n .where(eq(tables.entries.id, id))\n .limit(1),\n ),\n )\n return row as EntryRow | undefined\n })\n\n // An entry's `state` is not a column. The generated source reads the rest; the\n // state is derived from what is known of each entry, with this server's clock.\n const generated = source<P>(Db.Entry)\n const entries: EntitySource<P, DrizzleDatabase> = {\n ...generated,\n read: context =>\n Effect.gen(function* () {\n const wantsState = context.fields.includes('state')\n const fields = context.fields.filter(field => field !== 'state')\n const records = yield* generated.read({\n ...context,\n // The state needs these of each entry, asked for or not.\n fields: wantsState\n ? [...new Set([...fields, 'type', 'targetId', 'archivedAt'])]\n : fields,\n })\n if (!wantsState) return records\n const facts = yield* factsOf(\n records.map(record => ({\n id: record.id,\n type: String(record.values.type),\n targetId: (record.values.targetId as string | null) ?? null,\n label: '',\n archivedAt: (record.values.archivedAt as string | null) ?? null,\n revision: null,\n })),\n )\n const at = now()\n return records.map(record => ({\n id: record.id,\n values: {\n ...Object.fromEntries(\n Object.entries(record.values).filter(\n ([field]) => field === 'id' || context.fields.includes(field),\n ),\n ),\n state: Cms.state(facts.get(record.id)!, at),\n },\n }))\n }),\n }\n\n // The descriptor carries all three questions and the order; this says only\n // which table answers them. The audience boundary is unchanged: `visible`\n // on the binding is conjoined with the body, as for every source here.\n const worklist: QuerySource<P, DrizzleDatabase> = query<P, typeof Cms.Entries.Input.Type>(\n Cms.Entries,\n { entity: Db.Entry },\n )\n\n /** A mutation of this server: its principal and its database are fixed, its input is the descriptor's. */\n const operation = <Name extends string, Input, Output>(\n descriptor: MutationDescriptor<Name, Input, Output>,\n run: (context: {\n readonly input: Input\n readonly principal: P\n }) => Effect.Effect<MutationOutcome<Output>, RemoteServerError, DrizzleDatabase>,\n ): MutationSource<P, DrizzleDatabase> =>\n // Asked before anything is looked up: a visitor is not told which entries there are.\n // Then the whole of it is one transaction: a save that made an entry and\n // could not make its draft leaves neither.\n RemoteServer.mutation<P, DrizzleDatabase, Name, Input, Output>(descriptor, context =>\n isAuthor(context.principal)\n ? config.transaction(run(context))\n : Effect.fail(refuse('Only an author may change unpublished work')),\n )\n\n /**\n * A scheduled draft is published, when its time comes, as whoever scheduled it.\n * So changing it, replacing it or removing it is for someone who could have\n * scheduled it: otherwise an author who may not publish would publish through\n * someone who may.\n */\n const promised = (principal: P, entry: EntryRow) =>\n Effect.gen(function* () {\n const [draft] = yield* readRows(\n Db.Draft,\n { scheduledFor: tables.drafts.scheduledFor },\n entry.id,\n )\n if (draft?.scheduledFor == null) return\n if (config.allow?.(principal, 'schedule', entry) === false)\n return yield* refuse(\n 'This draft is scheduled, and only someone who may schedule it may change it',\n )\n })\n\n /** Whether the application lets this author do this, once the entry is known. */\n const asking = (principal: P, transition: Asked, entry: EntryRow | undefined) =>\n entry !== undefined && config.allow?.(principal, transition, entry) === false\n ? Effect.fail(refuse(`This author may not ${transition} this entry`))\n : Effect.void\n\n const draftFields = ['values', 'model', 'form', 'updatedAt', 'updatedBy', 'baseRevision']\n const draftPatch = returning(Db.Draft, draftFields)\n const entryPatch = returning(Db.Entry, [\n 'type',\n 'targetId',\n 'label',\n 'createdAt',\n 'archivedAt',\n 'revision',\n ])\n /**\n * The entry as the client should now hold it, its state with it: an operation\n * changes the state, and a patch without it would leave the old one on screen.\n */\n const entryPatches = (id: string) =>\n Effect.gen(function* () {\n const patches = entryPatch.patches(yield* readRows(Db.Entry, entryPatch.columns, id))\n const entry = yield* findEntry(id)\n if (entry === undefined) return patches\n const facts = (yield* factsOf([entry])).get(id)!\n return patches.map(patch => ({\n ...patch,\n values: { ...patch.values, state: Cms.state(facts, now()) },\n }))\n })\n const readRows = (binding: AnyEntityBinding, columns: Record<string, AnyColumn>, id: string) =>\n Effect.gen(function* () {\n const database = yield* DrizzleDatabase\n return yield* Effect.promise(() =>\n Promise.resolve(\n database.select(columns).from(binding.table).where(eq(binding.columns.id!, id)),\n ),\n )\n })\n\n const SaveDraft = operation(Cms.Operations.SaveDraft, ({ input, principal }) =>\n Effect.gen(function* () {\n if (!byType.has(input.type))\n return yield* refuse(`\"${input.type}\" is not a type of content this server knows`)\n const size = JSON.stringify([input.values, input.model]).length\n if (size > maxDraftSize)\n return yield* refuse(\n `This draft is too large to save: ${size} characters, and ${maxDraftSize} is the most`,\n )\n // An id nobody has is something new: the client named it, and this makes it.\n const existing = yield* findEntry(input.entry)\n if (existing !== undefined && existing.type !== input.type)\n return yield* refuse(`This entry is of \"${existing.type}\", not \"${input.type}\"`)\n if (existing?.archivedAt != null) return yield* refuse('An archived entry takes no draft')\n yield* asking(principal, 'save', existing)\n if (existing !== undefined) yield* promised(principal, existing)\n\n const database = (yield* DrizzleDatabase) as unknown as Writes\n const who = nameOf(principal)\n const id = existing?.id ?? input.entry\n const [held] = yield* readRows(Db.Draft, { updatedAt: tables.drafts.updatedAt }, id)\n const previous = held === undefined ? null : String(held.updatedAt)\n // Two saves in one millisecond must still be told apart by the next one.\n const at = now().toISOString()\n const updatedAt =\n previous !== null && at <= previous\n ? new Date(new Date(previous).getTime() + 1).toISOString()\n : at\n const written = {\n values: input.values,\n model: input.model,\n form: input.form,\n updatedAt,\n updatedBy: who,\n // A draft that changed is worth trying again when its time comes.\n scheduleError: null,\n }\n\n // The first draft of an entry has nothing to have been based on. Asked before\n // anything is written, so a refusal leaves no entry behind.\n if (previous === null && input.basedOn !== null)\n return yield* refuse('CmsConflict: this draft was discarded')\n if (existing === undefined) {\n yield* Effect.promise(() =>\n Promise.resolve(\n database.insert(tables.entries).values({\n id,\n type: input.type,\n targetId: null,\n label: input.label,\n createdBy: who,\n createdAt: at,\n archivedAt: null,\n revision: null,\n }),\n ),\n )\n }\n if (previous === null) {\n yield* Effect.promise(() =>\n Promise.resolve(\n database.insert(tables.drafts).values({ id, ...written, baseRevision: null }),\n ),\n )\n } else {\n // Compare and set: the save names what it was made from, and a newer one\n // on the server means someone else saved in between.\n const changed = yield* Effect.promise(() =>\n Promise.resolve(\n database\n .update(tables.drafts)\n .set(written)\n .where(\n and(eq(tables.drafts.id, id), eq(tables.drafts.updatedAt, input.basedOn ?? '')),\n )\n .returning({ id: tables.drafts.id }),\n ),\n )\n if (changed.length === 0)\n return yield* refuse('CmsConflict: this draft was saved by someone else since')\n }\n if (existing !== undefined && existing.label !== input.label) {\n yield* Effect.promise(() =>\n Promise.resolve(\n database\n .update(tables.entries)\n .set({ label: input.label })\n .where(eq(tables.entries.id, id))\n .returning({ id: tables.entries.id }),\n ),\n )\n }\n\n const entities = [\n ...(yield* entryPatches(id)),\n ...draftPatch.patches(yield* readRows(Db.Draft, draftPatch.columns, id)),\n ]\n return { output: { entry: id as never, updatedAt }, entities }\n }),\n )\n\n const DiscardDraft = operation(Cms.Operations.DiscardDraft, ({ input, principal }) =>\n Effect.gen(function* () {\n const entry = yield* findEntry(input.entry)\n if (entry === undefined) return yield* refuse('There is no such entry')\n yield* asking(principal, 'discard', entry)\n yield* promised(principal, entry)\n const database = (yield* DrizzleDatabase) as unknown as Writes\n yield* Effect.promise(() =>\n Promise.resolve(database.delete(tables.drafts).where(eq(tables.drafts.id, entry.id))),\n )\n const gone = [{ entity: 'CmsDraft', id: entry.id }]\n // Never published, and now with nothing entered: there is nothing left of it.\n if (entry.targetId !== null)\n return { output: {}, deleted: gone, entities: yield* entryPatches(entry.id) }\n yield* Effect.promise(() =>\n Promise.resolve(database.delete(tables.entries).where(eq(tables.entries.id, entry.id))),\n )\n return { output: {}, deleted: [...gone, { entity: 'CmsEntry', id: entry.id }] }\n }),\n )\n\n const done: Readonly<Record<Exclude<Asked, 'save' | 'discard'>, string>> = {\n publish: 'published',\n unpublish: 'unpublished',\n schedule: 'scheduled',\n unschedule: 'unscheduled',\n archive: 'archived',\n unarchive: 'unarchived',\n restore: 'restored',\n }\n /** The entry, if its state offers this transition now. */\n const offering = (id: string, transition: Exclude<Asked, 'save' | 'discard'>) =>\n Effect.gen(function* () {\n const entry = yield* findEntry(id)\n if (entry === undefined) return yield* refuse('There is no such entry')\n const served = byType.get(entry.type)\n if (served === undefined)\n return yield* refuse(`\"${entry.type}\" is not a type of content this server knows`)\n const facts = (yield* factsOf([entry])).get(entry.id)!\n if (!Cms.offers(facts, now(), served.type).includes(transition))\n return yield* refuse(`This entry cannot be ${done[transition]} as it stands`)\n return { entry, served, facts }\n })\n\n /** What the `published` role's column holds for \"now\". */\n const stamp = (column: AnyColumn, at: Date) => {\n const kind = column.dataType.split(' ')[0]\n return kind === 'string' ? at.toISOString() : kind === 'number' ? at.getTime() : at\n }\n\n const scheduledPatch = returning(Db.Draft, ['scheduledFor', 'scheduleError'])\n const revisionPatch = returning(Db.Revision, ['n', 'values', 'publishedAt', 'publishedBy'])\n\n type Found = Effect.Success<ReturnType<typeof offering>>\n\n /** The draft as the publish mutation would take it, or why it would not. */\n const readied = ({ entry, served, facts }: Found) =>\n Effect.gen(function* () {\n const [draft] = yield* readRows(Db.Draft, { values: tables.drafts.values }, entry.id)\n // A row that was deleted under its entry is made again.\n const creating = facts.row === 'none'\n const handler = creating ? served.create : served.update\n const value =\n creating || typeof draft?.values !== 'object' || draft.values === null\n ? draft?.values\n : { ...draft.values, id: entry.targetId }\n const decoded = yield* Schema.decodeUnknownEffect(handler.Input)(value).pipe(\n Effect.mapError(error => refuse(`This draft is not ready to publish: ${String(error)}`)),\n )\n return { draft, creating, handler, decoded }\n })\n\n /** A publish, for the operation that asks for one and for the schedule that comes due. */\n const publishing = (found: Found, principal: P, basedOn: number | null) =>\n Effect.gen(function* () {\n const { entry, served } = found\n const database = yield* DrizzleDatabase\n const held = entry.revision\n const conflict = refuse('CmsConflict: this entry was published by someone else since')\n if (held !== basedOn) return yield* conflict\n const { draft, creating, handler, decoded } = yield* readied(found)\n\n // A taken slug is refused by name, on its key. This is advice: two publishes\n // can both pass it, and then the unique index is the rule, below.\n const address = served.type.roles.slug\n const slug =\n address === undefined\n ? undefined\n : (decoded as Readonly<Record<string, unknown>> | null)?.[address.key]\n const taken = (key: string) => refuse(Cms.slugTaken.message(key, String(slug)))\n if (address !== undefined && typeof slug === 'string') {\n const column = served.binding.columns[address.key]!\n const id = served.binding.columns.id!\n const others = yield* Effect.promise(() =>\n Promise.resolve(\n database\n .select({ id })\n .from(served.binding.table)\n .where(and(eq(column, slug), creating ? undefined : ne(id, entry.targetId!)))\n .limit(1),\n ),\n )\n if (others.length > 0) return yield* taken(address.key)\n }\n\n return yield* Effect.gen(function* () {\n const writes = (yield* DrizzleDatabase) as unknown as Writes\n const n = (held ?? 0) + 1\n // Compare and set, first: of two publishes made from one revision, one\n // finds the number already moved, and nothing of it is written.\n const moved = yield* Effect.promise(() =>\n Promise.resolve(\n writes\n .update(tables.entries)\n .set({ revision: n })\n .where(\n and(\n eq(tables.entries.id, entry.id),\n held === null\n ? isNull(tables.entries.revision)\n : eq(tables.entries.revision, held),\n ),\n )\n .returning({ id: tables.entries.id }),\n ),\n )\n if (moved.length === 0) return yield* conflict\n const ran = yield* handler.run({ input: decoded, principal })\n const targetId = creating\n ? String((ran.output as { readonly id: unknown }).id)\n : entry.targetId!\n const at = now()\n const shown = served.type.roles.published\n if (shown !== undefined) {\n // Publishing shows the row. One already shown keeps its first date.\n const column = served.binding.columns[shown.key]!\n yield* Effect.promise(() =>\n Promise.resolve(\n writes\n .update(served.binding.table)\n .set({ [shown.key]: stamp(column, at) })\n .where(and(eq(served.binding.columns.id!, targetId), isNull(column)))\n .returning({ id: served.binding.columns.id! }),\n ),\n )\n }\n const revisionId = `${entry.id}:${n}`\n yield* Effect.promise(() =>\n Promise.resolve(\n writes.insert(tables.revisions).values({\n id: revisionId,\n entryId: entry.id,\n n,\n values: draft?.values,\n publishedAt: at.toISOString(),\n publishedBy: nameOf(principal),\n }),\n ),\n )\n yield* Effect.promise(() =>\n Promise.resolve(writes.delete(tables.drafts).where(eq(tables.drafts.id, entry.id))),\n )\n yield* Effect.promise(() =>\n Promise.resolve(\n writes\n .update(tables.entries)\n .set({ targetId })\n .where(eq(tables.entries.id, entry.id))\n .returning({ id: tables.entries.id }),\n ),\n )\n const content = returning(served.binding, shown === undefined ? [] : [shown.key])\n return {\n output: { entry: entry.id as never, targetId, revision: n },\n entities: [\n ...ran.entities,\n ...content.patches(yield* readRows(served.binding, content.columns, targetId)),\n ...(yield* entryPatches(entry.id)),\n ...revisionPatch.patches(\n yield* readRows(Db.Revision, revisionPatch.columns, revisionId),\n ),\n ],\n connections: ran.connections,\n deleted: [...ran.deleted, { entity: 'CmsDraft', id: entry.id }],\n }\n }).pipe(\n // The publish that lost the race: the index refused it, and it is the same\n // news as the check's. Any other defect is left as it was.\n Effect.catchDefect(defect =>\n address !== undefined &&\n refusedAsDuplicate(defect, served.binding.columns[address.key]!.name)\n ? Effect.fail(taken(address.key))\n : Effect.die(defect),\n ),\n )\n })\n\n const Publish = operation(Cms.Operations.Publish, ({ input, principal }) =>\n Effect.gen(function* () {\n const found = yield* offering(input.entry, 'publish')\n yield* asking(principal, 'publish', found.entry)\n return yield* publishing(found, principal, input.basedOn)\n }),\n )\n\n /** Writes to an entry's draft, and answers with both as the client should now hold them. */\n const drafted = (id: string, values: object) =>\n Effect.gen(function* () {\n const writes = (yield* DrizzleDatabase) as unknown as Writes\n yield* Effect.promise(() =>\n Promise.resolve(\n writes\n .update(tables.drafts)\n .set(values)\n .where(eq(tables.drafts.id, id))\n .returning({ id: tables.drafts.id }),\n ),\n )\n return {\n output: {},\n entities: [\n ...(yield* entryPatches(id)),\n ...scheduledPatch.patches(yield* readRows(Db.Draft, scheduledPatch.columns, id)),\n ],\n }\n })\n\n const Schedule = operation(Cms.Operations.Schedule, ({ input, principal }) =>\n Effect.gen(function* () {\n const found = yield* offering(input.entry, 'schedule')\n yield* asking(principal, 'schedule', found.entry)\n if (Number.isNaN(new Date(input.at).getTime()))\n return yield* refuse(`\"${input.at}\" is not a time`)\n // What cannot be published now is not promised for later.\n yield* readied(found)\n return yield* drafted(found.entry.id, {\n scheduledFor: new Date(input.at).toISOString(),\n scheduledBy: nameOf(principal),\n scheduleError: null,\n })\n }),\n )\n\n const Unschedule = operation(Cms.Operations.Unschedule, ({ input, principal }) =>\n Effect.gen(function* () {\n const found = yield* offering(input.entry, 'unschedule')\n yield* asking(principal, 'unschedule', found.entry)\n return yield* drafted(found.entry.id, {\n scheduledFor: null,\n scheduledBy: null,\n scheduleError: null,\n })\n }),\n )\n\n /** Archiving and its undoing: a fact about the entry, and for what can be hidden, the row. */\n const archiving = (transition: 'archive' | 'unarchive') =>\n operation(\n transition === 'archive' ? Cms.Operations.Archive : Cms.Operations.Unarchive,\n ({ input, principal }) =>\n Effect.gen(function* () {\n const { entry, served } = yield* offering(input.entry, transition)\n yield* asking(principal, transition, entry)\n const writes = (yield* DrizzleDatabase) as unknown as Writes\n yield* Effect.promise(() =>\n Promise.resolve(\n writes\n .update(tables.entries)\n .set({ archivedAt: transition === 'archive' ? now().toISOString() : null })\n .where(eq(tables.entries.id, entry.id))\n .returning({ id: tables.entries.id }),\n ),\n )\n const shown = served.type.roles.published\n if (transition === 'unarchive' || shown === undefined || entry.targetId === null)\n return { output: {}, entities: yield* entryPatches(entry.id) }\n // What is put away is not left on show. It comes back as unpublished work.\n yield* Effect.promise(() =>\n Promise.resolve(\n writes\n .update(served.binding.table)\n .set({ [shown.key]: null })\n .where(eq(served.binding.columns.id!, entry.targetId!))\n .returning({ id: served.binding.columns.id! }),\n ),\n )\n const content = returning(served.binding, [shown.key])\n return {\n output: {},\n entities: [\n ...content.patches(\n yield* readRows(served.binding, content.columns, entry.targetId),\n ),\n ...(yield* entryPatches(entry.id)),\n ],\n }\n }),\n )\n\n /**\n * A revision's value becomes the working copy, and nothing is published. It\n * replaces what the draft held, and takes back a promise made of that: what\n * was scheduled is not what is there now. The saved Model goes too, so an\n * editor fills its form from the values, key by key.\n */\n const Restore = operation(Cms.Operations.Restore, ({ input, principal }) =>\n Effect.gen(function* () {\n const { entry } = yield* offering(input.entry, 'restore')\n yield* asking(principal, 'restore', entry)\n yield* promised(principal, entry)\n const database = yield* DrizzleDatabase\n const [revision] = yield* Effect.promise(() =>\n Promise.resolve(\n database\n .select({ values: tables.revisions.values })\n .from(tables.revisions)\n .where(\n and(eq(tables.revisions.entryId, entry.id), eq(tables.revisions.n, input.revision)),\n )\n .limit(1),\n ),\n )\n if (revision === undefined)\n return yield* refuse(`This entry has no revision ${input.revision}`)\n\n const writes = database as unknown as Writes\n const [held] = yield* readRows(Db.Draft, { updatedAt: tables.drafts.updatedAt }, entry.id)\n const at = now().toISOString()\n const updatedAt =\n held !== undefined && at <= String(held.updatedAt)\n ? new Date(new Date(String(held.updatedAt)).getTime() + 1).toISOString()\n : at\n const restored = {\n values: revision.values,\n model: null,\n form: `restored@${input.revision}`,\n updatedAt,\n updatedBy: nameOf(principal),\n baseRevision: entry.revision,\n scheduledFor: null,\n scheduledBy: null,\n scheduleError: null,\n }\n yield* Effect.promise(() =>\n Promise.resolve(\n held === undefined\n ? writes.insert(tables.drafts).values({ id: entry.id, ...restored })\n : writes\n .update(tables.drafts)\n .set(restored)\n .where(eq(tables.drafts.id, entry.id))\n .returning({ id: tables.drafts.id }),\n ),\n )\n return {\n output: { updatedAt },\n entities: [\n ...(yield* entryPatches(entry.id)),\n ...draftPatch.patches(yield* readRows(Db.Draft, draftPatch.columns, entry.id)),\n ...scheduledPatch.patches(yield* readRows(Db.Draft, scheduledPatch.columns, entry.id)),\n ],\n }\n }),\n )\n\n /**\n * Publishes every draft whose time has come, each in its own transaction, as\n * whoever scheduled it: `as` says who a stored name is. One that fails stays\n * scheduled with the reason, and is left alone until its draft changes, so a\n * fault the author must fix is not tried again every minute. The package owns\n * no timer: a cron trigger, an interval or a queue calls this.\n */\n const due = (at: Date, options: { readonly as: (scheduledBy: string | null) => P }) =>\n Effect.gen(function* () {\n const database = yield* DrizzleDatabase\n const waiting = yield* Effect.promise(() =>\n Promise.resolve(\n database\n .select({ id: tables.drafts.id, scheduledBy: tables.drafts.scheduledBy })\n .from(tables.drafts)\n .where(\n and(\n isNotNull(tables.drafts.scheduledFor),\n lte(tables.drafts.scheduledFor, at.toISOString()),\n isNull(tables.drafts.scheduleError),\n // What is put away keeps its promise, and keeps it waiting.\n sql`${tables.drafts.id} in (select ${tables.entries.id} from ${tables.entries} where ${tables.entries.archivedAt} is null)`,\n ),\n ),\n ),\n )\n const outcomes: Array<{ readonly entry: string; readonly error: string | null }> = []\n for (const draft of waiting) {\n const id = String(draft.id)\n const principal = options.as((draft.scheduledBy as string | null) ?? null)\n const error = yield* config\n .transaction(\n Effect.gen(function* () {\n if (!isAuthor(principal))\n return yield* refuse('Whoever scheduled this is no longer an author')\n const found = yield* offering(id, 'publish')\n yield* asking(principal, 'publish', found.entry)\n yield* publishing(found, principal, found.entry.revision)\n return null\n }),\n )\n .pipe(\n Effect.catch(failure => Effect.succeed(failure.message)),\n Effect.catchDefect(defect => Effect.succeed(String(defect))),\n )\n // Recorded after the failed publish was undone, or it would be undone with it.\n if (error !== null) yield* config.transaction(drafted(id, { scheduleError: error }))\n outcomes.push({ entry: id, error })\n }\n return outcomes\n })\n\n const Unpublish = operation(Cms.Operations.Unpublish, ({ input, principal }) =>\n Effect.gen(function* () {\n const { entry, served } = yield* offering(input.entry, 'unpublish')\n yield* asking(principal, 'unpublish', entry)\n const shown = served.type.roles.published!\n const writes = (yield* DrizzleDatabase) as unknown as Writes\n yield* Effect.promise(() =>\n Promise.resolve(\n writes\n .update(served.binding.table)\n .set({ [shown.key]: null })\n .where(eq(served.binding.columns.id!, entry.targetId!))\n .returning({ id: served.binding.columns.id! }),\n ),\n )\n const content = returning(served.binding, [shown.key])\n return {\n output: {},\n entities: [\n ...content.patches(yield* readRows(served.binding, content.columns, entry.targetId!)),\n ...(yield* entryPatches(entry.id)),\n ],\n }\n }),\n )\n\n const sources: ReadonlyArray<EntitySource<P, DrizzleDatabase>> = [\n entries,\n source<P>(Db.Draft),\n source<P>(Db.Revision),\n ...config.content.map(served => source<P>(served.binding)),\n ]\n const mutations: ReadonlyArray<MutationSource<P, DrizzleDatabase>> = [\n SaveDraft,\n DiscardDraft,\n Publish,\n Unpublish,\n Schedule,\n Unschedule,\n archiving('archive'),\n archiving('unarchive'),\n Restore,\n ]\n\n // A content type with an address is found by it, behind the same boundary as\n // every other read of its table.\n // The descriptor carries what the query means, so this registers the source\n // and says no more: the address column and the order come from the body,\n // through the binding that knows which column holds which field.\n const bySlug = config.content.flatMap(({ type, binding }) =>\n type.roles.slug === undefined\n ? []\n : [\n query<P, { readonly slug: string }>(Cms.bySlug(type), {\n entity: binding,\n }) as QuerySource<P, DrizzleDatabase>,\n ],\n )\n\n return {\n /**\n * The sources of the content types and of the CMS's own Entities, each behind\n * the audience boundary. Register these and not `source(binding)` of a content\n * table: that is how the boundary cannot be forgotten.\n */\n sources,\n queries: [worklist, ...bySlug] as ReadonlyArray<QuerySource<P, DrizzleDatabase>>,\n mutations,\n due,\n /** The bindings of `Entry`, `Draft` and `Revision`, for a handler that returns patches of them. */\n bindings: Db,\n }\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAeA,MAAa,sBAAsB;CACjC,SAAS,YAAY,eAAe;EAClC,IAAIA,OAAK,IAAI,CAAC,CAAC,WAAW;EAC1B,MAAMA,OAAK,MAAM,CAAC,CAAC,QAAQ;EAC3B,UAAUA,OAAK,WAAW;EAC1B,OAAOA,OAAK,OAAO,CAAC,CAAC,QAAQ;EAC7B,WAAWA,OAAK,YAAY;EAC5B,WAAWA,OAAK,YAAY,CAAC,CAAC,QAAQ;EACtC,YAAYA,OAAK,aAAa;EAC9B,UAAUC,UAAQ,UAAU;CAC9B,CAAC;CACD,QAAQ,YAAY,cAAc;EAChC,IAAID,OAAK,IAAI,CAAC,CAAC,WAAW;EAC1B,QAAQA,OAAK,UAAU,EAAE,MAAM,OAAO,CAAC;EACvC,OAAOA,OAAK,SAAS,EAAE,MAAM,OAAO,CAAC;EACrC,MAAMA,OAAK,MAAM,CAAC,CAAC,QAAQ;EAC3B,WAAWA,OAAK,YAAY,CAAC,CAAC,QAAQ;EACtC,WAAWA,OAAK,YAAY;EAC5B,cAAcC,UAAQ,eAAe;EACrC,cAAcD,OAAK,eAAe;EAClC,aAAaA,OAAK,cAAc;EAChC,eAAeA,OAAK,gBAAgB;CACtC,CAAC;CACD,WAAW,YAAY,iBAAiB;EACtC,IAAIA,OAAK,IAAI,CAAC,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AO,SAAS,MAAM,OAAO,WAAW;EAClE,OAAO,OAAO,WAAW,aAAa,KAAK;EAC3C,MAAM,QAAQ,OAAO,KAAK,MAAM;EAChC,MAAM,SAAU,OAAO;EACvB,OAAO,OAAO,cACZ,QAAQ,QACN,OACG,OAAO,OAAO,QAAQ,KAAK,CAAC,CAC5B,IAAI,GAAG,MAAM,MAAM,KAAK,CAAC,CAAC,CAC1B,MAAM,GAAG,OAAO,QAAQ,QAAQ,IAAK,MAAM,QAAS,CAAC,CAAC,CACtD,UAAU,EAAE,IAAI,OAAO,QAAQ,QAAQ,GAAI,CAAC,CACjD,CACF;EACA,MAAM,UAAU,UAAU,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC;EACrD,OAAO;GACL,QAAQ,CAAC;GACT,UAAU,CACR,GAAG,QAAQ,QAAQ,OAAO,SAAS,OAAO,SAAS,QAAQ,SAAS,MAAM,QAAS,CAAC,GACpF,GAAI,OAAO,aAAa,MAAM,EAAE,CAClC;EACF;CACF,CAAC,CACH;CAEA,MAAM,UAA2D;EAC/D;EACA,OAAU,GAAG,KAAK;EAClB,OAAU,GAAG,QAAQ;EACrB,GAAG,OAAO,QAAQ,KAAI,WAAU,OAAU,OAAO,OAAO,CAAC;CAC3D;CACA,MAAM,YAA+D;EACnE;EACA;EACA;EACA;EACA;EACA;EACA,UAAU,SAAS;EACnB,UAAU,WAAW;EACrB;CACF;CAiBA,OAAO;;;;;;EAML;EACA,SAAS,CAAC,UAAU,GAjBP,OAAO,QAAQ,SAAS,EAAE,MAAM,cAC7C,KAAK,MAAM,SAAS,KAAA,IAChB,CAAC,IACD,CACE,MAAoC,IAAI,OAAO,IAAI,GAAG,EACpD,QAAQ,QACV,CAAC,CACH,CAUwB,CAAC;EAC7B;EACA;;EAEA,UAAU;CACZ;AACF,EACF"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "foldkit-cms-drizzle",
3
+ "version": "0.1.0",
4
+ "description": "The server half of foldkit-cms over Drizzle: the entries, drafts and revisions tables, the draft operations with their conflict rule, the worklist query, and the audience boundary between a visitor and an author.",
5
+ "keywords": [
6
+ "foldkit",
7
+ "effect",
8
+ "cms",
9
+ "drizzle",
10
+ "drafts",
11
+ "typescript"
12
+ ],
13
+ "type": "module",
14
+ "license": "MIT",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "author": "Patrick Glenn <doeixd@gmail.com>",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/doeixd/foldkit-plus.git",
22
+ "directory": "packages/cms-drizzle"
23
+ },
24
+ "homepage": "https://github.com/doeixd/foldkit-plus/tree/main/packages/cms-drizzle#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/doeixd/foldkit-plus/issues"
27
+ },
28
+ "sideEffects": false,
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.mts",
32
+ "import": "./dist/index.mjs"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "dependencies": {
41
+ "drizzle-orm": "1.0.0-rc.4",
42
+ "foldkit-cms": "0.1.0",
43
+ "foldkit-remote": "0.5.0",
44
+ "foldkit-remote-server": "0.5.0",
45
+ "foldkit-remote-drizzle": "0.5.0",
46
+ "foldkit-entity": "0.2.0"
47
+ },
48
+ "peerDependencies": {
49
+ "effect": "^4.0.0-rc.112"
50
+ },
51
+ "devDependencies": {
52
+ "effect": "4.0.0-rc.112",
53
+ "foldkit": "0.158.2",
54
+ "tsdown": "^0.23.0",
55
+ "typescript": "5.9.3",
56
+ "foldkit-bundle": "0.2.0",
57
+ "foldkit-form": "0.1.1",
58
+ "foldkit-surface": "0.3.0"
59
+ },
60
+ "scripts": {
61
+ "build": "tsdown",
62
+ "typecheck": "tsc -b"
63
+ }
64
+ }