file-provider-inmemory
Registers an in-process "inmemory" provider for file-foundation that stores file bytes per tenant in a module-level Map. Use listKeys(tenantId) and clearStorage(tenantId) in demo apps and tests; not for production (data is lost on restart and grows without bound).
Quick example
Section titled “Quick example”From apps-user-data-rights-demo — the smallest working mount:
// kumiko-feature-version: 1//// todos — demo domain feature that integrates into user-data-// rights via EXT_USER_DATA. An app author registers one// (export, delete) hook per domain entity — that's it. Forget cron, export bundle and// GDPR endpoints come entirely from user-data-rights.//// This feature shows:// - r.entity({ name: "todo", ...todoEntity }) → Drizzle table is built// - r.writeHandler({ name: "create", … }) → user creates a todo// - r.queryHandler({ name: "list", … }) → user sees their todos// - r.applyExtension({ name: EXT_USER_DATA, entity: "todo" }) → forget + export integration//// What happens when the user then calls request-export:// 1. user-data-rights.request-export.write triggers a job// 2. The worker iterates all EXT_USER_DATA providers (user, fileRef, todo)// 3. todoExportHook reads all rows with author_id = userId from// ALL of the user's tenants// 4. The bundle is packed as a ZIP behind a signed magic link and sent by// email//// What happens when the user calls request-deletion:// 1. user-data-rights sets status=DeletionRequested + grace// 2. After it expires the run-forget-cleanup cron runs// 3. todoDeleteHook DELETEs all rows with author_id = userId// 4. The user is anonymized (display_name="(deleted)", email=null)
import { UserDataRightsScreens } from "@cosmicdrift/kumiko-bundled-features/user-data-rights";import { deleteMany, deriveEntityTableMeta, insertOne, selectMany, updateMany,} from "@cosmicdrift/kumiko-framework/db";import { createEntity, createTextField, defineFeature, defineQueryHandler, defineWriteHandler, EXT_USER_DATA, type UserDataDeleteHook, type UserDataExportHook,} from "@cosmicdrift/kumiko-framework/engine";import { z } from "zod";
const FEATURE_NAME = "todos";
export const todoEntity = createEntity({ name: "todo", table: "store_todos", idType: "uuid", fields: { // nullable: on GDPR anonymize authorId is set to null // (row stays, personal reference removed). Pattern matches fileRef. authorId: createTextField({ personal: "ref" }), title: createTextField({ personal: false, reason: "is_business_data", required: true, maxLength: 200, }), // Plaintext on purpose: store_todos is an unmanaged direct-write store, so the // PII executor never encrypts it. Art. 17 runs through the EXT_USER_DATA // hook below instead (deletes the author's rows, or unlinks them on anonymize). body: createTextField({ personal: false, reason: "covered_by_user_data_hook", maxLength: 4000, }), },});
// Plain EntityTableMeta, NOT a branded EntityTable: store_todos is a deliberate// unmanaged direct-write store (r.storeTable below), so the create handler +// forget hook write it directly — the meta carries no executor-only brand.export const todosTable = deriveEntityTableMeta(todoEntity, { source: "unmanaged" });
const createSchema = z.object({ title: z.string().min(1).max(200), body: z.string().max(4000).optional(),});
const createTodoHandler = defineWriteHandler({ name: "create", schema: createSchema, access: { openToAll: { reason: "any signed-in tenant user may create their own todo; the author id is " + "stamped server-side from the caller, never client-supplied", }, }, handler: async (event, ctx) => { const id = crypto.randomUUID(); await insertOne(ctx.db, todosTable, { id, tenantId: event.user.tenantId, authorId: event.user.id, title: event.payload.title, body: event.payload.body ?? "", }); return { isSuccess: true as const, data: { id } }; },});
const listTodosHandler = defineQueryHandler({ name: "list", schema: z.object({}), access: { openToAll: { reason: "any signed-in tenant user lists only their own todos; the query filters " + "by authorId = the caller's own id", }, }, handler: async (query, ctx) => { const rows = await selectMany<{ id: string; title: string; body: string }>(ctx.db, todosTable, { authorId: query.user.id, }); return { rows }; },});
export const todosFeature = defineFeature(FEATURE_NAME, (r) => { r.requires({ features: ["user-data-rights"] });
// store_todos is a direct-write store: the create handler `insertOne`s and // the forget hook `updateMany`/`deleteMany`s rows WITHOUT emitting lifecycle // events. Registering it as r.entity would make it a rebuildable implicit // projection whose replay finds zero todo events and swaps an empty shadow // over the live table — wiping every todo (and silently un-forgetting // anonymized rows) on the next projection rebuild (#498). r.storeTable // keeps the migration DDL but opts the table out of implicit rebuild. r.storeTable(todosTable, { reason: "read_side.todos_direct_write", }); r.writeHandler(createTodoHandler); r.queryHandler(listTodosHandler);
// EXT_USER_DATA-Hooks: wie todos zu DSGVO-Pipeline beitragen. // Cross-tenant: Hook wird pro Tenant des Users aufgerufen — wir filtern // hier on (tenantId, authorId), beide kommen aus dem ctx. const exportTodos: UserDataExportHook = async (ctx) => { const rows = await selectMany<{ id: string; title: string; body: string }>(ctx.db, todosTable, { tenantId: ctx.tenantId, authorId: ctx.userId, }); if (rows.length === 0) return null; return { entity: "todo", rows: rows.map((row) => ({ id: String(row.id), title: row.title ?? "", body: row.body ?? "", })), }; };
// Strategy-aware: bei "anonymize" bleibt die Row (authorId=null) damit // Multi-User-Refs intakt bleiben; bei "delete" hard-delete. Compliance- // Profile (DE-HR, Steuer) koennen via retention.strategy=anonymize den // anonymize-Pfad triggern statt hardDelete. Pattern matched fileRef-hook. const deleteTodos: UserDataDeleteHook = async (ctx, strategy) => { const where = { tenantId: ctx.tenantId, authorId: ctx.userId }; if (strategy === "anonymize") { await updateMany(ctx.db, todosTable, { authorId: null }, where); } else { await deleteMany(ctx.db, todosTable, where); } };
r.applyExtension({ name: EXT_USER_DATA, entity: "todo", export: exportTodos, delete: deleteTodos, });
// Wire-proof for the read-only GDPR inspector screens: an app opts in by // navigating the (otherwise inert) bundled screens. SystemAdmin-gated, so // they surface only for platform operators. This nav is the ONLY wiring an // app needs — the screens and convention handlers live in user-data-rights. r.nav({ id: "gdpr-export-jobs", label: "GDPR · Export Jobs", icon: "shield", screen: UserDataRightsScreens.exportJobList, access: { roles: ["SystemAdmin"] }, order: 90, }); r.nav({ id: "gdpr-download-attempts", label: "GDPR · Download Attempts", icon: "download", screen: UserDataRightsScreens.downloadAttemptList, access: { roles: ["SystemAdmin"] }, order: 91, });});
export const TODO_CREATE_QN = "todos:write:create";export const TODO_LIST_QN = "todos:query:list";📄 On GitHub: samples/apps/user-data-rights-demo/src/feature.ts
How it fits
Section titled “How it fits”What this feature needs to run (Requires).
flowchart TB
n_file_provider_inmemory["file-provider-inmemory"]
subgraph how_reqs["Requires"]
n_file_foundation["file-foundation"]
end
n_file_foundation --> n_file_provider_inmemory
Getting started
Section titled “Getting started”Start with apps-user-data-rights-demo for a step-by-step walkthrough with runnable code and integration tests.
Dependencies
Section titled “Dependencies”- Requires:
file-foundation - Activation: always on (not toggleable)
Extensions & cross-feature APIs
Section titled “Extensions & cross-feature APIs”- Registers extension:
fileProvider→inmemory