Skip to content

refactor: Pass service context to create / update / delete operations#700

Merged
kingston merged 1 commit into
mainfrom
kingston/eng-917-pass-service-context-to-create-update-operations
Nov 26, 2025
Merged

refactor: Pass service context to create / update / delete operations#700
kingston merged 1 commit into
mainfrom
kingston/eng-917-pass-service-context-to-create-update-operations

Conversation

@kingston

@kingston kingston commented Nov 26, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Data operations (create, update, delete) now have access to service context, enabling better tracking of user actions such as recording who created or modified records.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel

vercel Bot commented Nov 26, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
baseplate-project-builder-web Ready Ready Preview Comment Nov 26, 2025 1:28am

@changeset-bot

changeset-bot Bot commented Nov 26, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: def444f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 18 packages
Name Type
@baseplate-dev/fastify-generators Patch
@baseplate-dev/project-builder-server Patch
@baseplate-dev/plugin-auth Patch
@baseplate-dev/plugin-queue Patch
@baseplate-dev/plugin-storage Patch
@baseplate-dev/project-builder-cli Patch
@baseplate-dev/project-builder-common Patch
@baseplate-dev/project-builder-test Patch
@baseplate-dev/project-builder-web Patch
@baseplate-dev/create-project Patch
@baseplate-dev/code-morph Patch
@baseplate-dev/core-generators Patch
@baseplate-dev/project-builder-lib Patch
@baseplate-dev/react-generators Patch
@baseplate-dev/sync Patch
@baseplate-dev/tools Patch
@baseplate-dev/ui-components Patch
@baseplate-dev/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 26, 2025

Copy link
Copy Markdown

Walkthrough

Adds serviceContext parameter to create, update, and delete operation configurations across the fastify-generators template and example projects. The serviceContext is now threaded through operation implementations to enable access to user context during data operations.

Changes

Cohort / File(s) Change Summary
Changeset Documentation
.changeset/lemon-swans-sink.md
Introduces changeset entry documenting the patch release for @baseplate-dev/fastify-generators with functional change for passing service context to create, update, and delete operations
Fastify Generators Template
packages/fastify-generators/src/generators/prisma/data-utils/templates/src/utils/data-operations/define-operations.ts
Augments CreateOperationConfig.create, UpdateOperationConfig.update, and DeleteOperationConfig.delete signatures to accept serviceContext: ServiceContext parameter. Updates defineCreateOperation, defineUpdateOperation, and defineDeleteOperation implementations to forward serviceContext into operation configs. Includes documentation examples showing serviceContext usage for populating createdById and updatedById fields
Example Projects
examples/blog-with-auth/apps/backend/src/utils/data-operations/define-operations.ts,
examples/todo-with-auth0/apps/backend/src/utils/data-operations/define-operations.ts
Mirrors template changes: updates operation config signatures to include serviceContext parameter and threads context through operation function implementations. Example signatures updated to document new parameter

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Pattern consistency: The same parameter threading pattern is applied homogeneously across three files
  • Areas for attention:
    • Verify serviceContext is properly propagated from request context through all three operation types (create, update, delete)
    • Confirm type safety of ServiceContext interface across template and example implementations
    • Validate that examples correctly demonstrate createdById/updatedById population from serviceContext.user.id

Possibly related PRs

  • halfdomelabs/baseplate#692: Directly modifies the same data-operations API by wiring serviceContext into create/update/delete operation signatures and implementations

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: passing service context to create, update, and delete operations across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kingston/eng-917-pass-service-context-to-create-update-operations

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4be6c7d and def444f.

⛔ Files ignored due to path filters (6)
  • examples/blog-with-auth/apps/backend/baseplate/generated/src/utils/data-operations/define-operations.ts is excluded by !**/generated/**, !**/generated/**
  • examples/todo-with-auth0/apps/backend/baseplate/generated/src/utils/data-operations/define-operations.ts is excluded by !**/generated/**, !**/generated/**
  • tests/simple/apps/backend/baseplate/generated/src/utils/data-operations/define-operations.ts is excluded by !**/generated/**, !tests/**, !**/generated/**
  • tests/simple/apps/backend/src/utils/data-operations/define-operations.ts is excluded by !tests/**
  • tests/simple/baseplate/generated/package.json is excluded by !**/generated/**, !tests/**, !**/generated/**
  • tests/simple/package.json is excluded by !tests/**
📒 Files selected for processing (4)
  • .changeset/lemon-swans-sink.md (1 hunks)
  • examples/blog-with-auth/apps/backend/src/utils/data-operations/define-operations.ts (9 hunks)
  • examples/todo-with-auth0/apps/backend/src/utils/data-operations/define-operations.ts (9 hunks)
  • packages/fastify-generators/src/generators/prisma/data-utils/templates/src/utils/data-operations/define-operations.ts (9 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
.changeset/*.md

📄 CodeRabbit inference engine (AGENTS.md)

Add a new Changeset in the .changeset/ directory for new features or changes, with format 'package-name': patch and description of the feature or change

Files:

  • .changeset/lemon-swans-sink.md
examples/todo-with-auth0/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (examples/todo-with-auth0/CLAUDE.md)

Always use .js extensions in import statements, even for TypeScript files. Example: import { getSystemInfo } from '@src/system-info.js';

Files:

  • examples/todo-with-auth0/apps/backend/src/utils/data-operations/define-operations.ts
examples/todo-with-auth0/**/*.{ts,tsx}

📄 CodeRabbit inference engine (examples/todo-with-auth0/CLAUDE.md)

examples/todo-with-auth0/**/*.{ts,tsx}: Use import type for type-only imports
Always specify explicit return types for functions
Add JSDocs to all exported functions, interfaces, and classes with documentation of the function, its parameters, return value, and all fields

Files:

  • examples/todo-with-auth0/apps/backend/src/utils/data-operations/define-operations.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/code-style.mdc)

**/*.{ts,tsx}: Use TypeScript with strict type checking enabled
Always include return types on top-level functions including React components (React.ReactElement)
Include absolute paths in import statements via tsconfig paths (@src/ is the alias for src/)
If a particular interface or type is not exported, change the file so it is exported
If caught on a typing loop where forcing the any type is necessary, do not iterate too much - leave the typing as broken and let the user fix it

If target code is not easily testable, refactor it to be more testable (e.g., export types or functions)

**/*.{ts,tsx}: Import components from '@baseplate-dev/ui-components' package for UI development (e.g., Button, Input, Card, Dialog, etc.)
Use form components with React Hook Form controller variants (InputField, TextareaField, SelectField, CheckboxField, SwitchField, ComboboxField, MultiComboboxField, ColorPickerField, DatePickerField, DateTimePickerField)
Use SidebarLayout, Card, Breadcrumb, NavigationMenu, and NavigationTabs components for consistent layout structure from @baseplate-dev/ui-components
Use Dialog, ConfirmDialog, and useConfirmDialog from @baseplate-dev/ui-components for modal dialogs and confirmation interactions
Always use compareStrings from @baseplate-dev/utils instead of String.prototype.localeCompare() for code generation, file sorting, and internal data structures
If a particular interface or type is not exported, modify the file to export it
Use TsCodeFragment for composable code pieces and TsCodeUtils for manipulating fragments when generating TypeScript code
Create generators using createGenerator with configuration via descriptor schema (Zod), organizing into one or more tasks created with createGeneratorTask
Tasks should have run (initialization) and build (code generation) phases, export and consume providers, and may be organized into phases for ordered execution
Use provider scopes to control visibility and prevent collisions be...

Files:

  • examples/todo-with-auth0/apps/backend/src/utils/data-operations/define-operations.ts
  • examples/blog-with-auth/apps/backend/src/utils/data-operations/define-operations.ts
  • packages/fastify-generators/src/generators/prisma/data-utils/templates/src/utils/data-operations/define-operations.ts
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/code-style.mdc)

**/*.{ts,tsx,js}: Node 16 module resolution - include file extensions in imports (.js)
Sort imports by group: external libs first, then local imports
Use camelCase for variables/functions, PascalCase for types/classes
Order functions such that functions are placed below the variables/functions they use
Prefer using nullish coalescing operator (??) instead of logical or (||), enforced via ESLint rule
Prefer barrel exports e.g. export * from './foo.js' instead of individual named exports
Use console.info/warn/error instead of console.log

Files:

  • examples/todo-with-auth0/apps/backend/src/utils/data-operations/define-operations.ts
  • examples/blog-with-auth/apps/backend/src/utils/data-operations/define-operations.ts
  • packages/fastify-generators/src/generators/prisma/data-utils/templates/src/utils/data-operations/define-operations.ts
examples/blog-with-auth/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (examples/blog-with-auth/CLAUDE.md)

examples/blog-with-auth/**/*.{ts,tsx,js,jsx}: Always use .js extensions in import statements, even for TypeScript files (e.g., import { getSystemInfo } from '@src/system-info.js';)
Follow ESM module resolution with TypeScript's NodeNext setting
Add JSDocs to all exported functions, interfaces, and classes with documentation of the function, its parameters, return value, and all fields

Files:

  • examples/blog-with-auth/apps/backend/src/utils/data-operations/define-operations.ts
examples/blog-with-auth/**/*.{ts,tsx}

📄 CodeRabbit inference engine (examples/blog-with-auth/CLAUDE.md)

examples/blog-with-auth/**/*.{ts,tsx}: Use import type for type-only imports in TypeScript
Always specify explicit return types for functions in TypeScript

Files:

  • examples/blog-with-auth/apps/backend/src/utils/data-operations/define-operations.ts
🧠 Learnings (3)
📚 Learning: 2025-11-25T22:46:20.497Z
Learnt from: CR
Repo: halfdomelabs/baseplate PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:46:20.497Z
Learning: Applies to .changeset/*.md : Add a new Changeset in the `.changeset/` directory for new features or changes, with format `'package-name': patch` and description of the feature or change

Applied to files:

  • .changeset/lemon-swans-sink.md
📚 Learning: 2025-11-24T19:44:46.494Z
Learnt from: CR
Repo: halfdomelabs/baseplate PR: 0
File: examples/todo-with-auth0/CLAUDE.md:0-0
Timestamp: 2025-11-24T19:44:46.494Z
Learning: Applies to examples/todo-with-auth0/**/*.{ts,tsx} : Add JSDocs to all exported functions, interfaces, and classes with documentation of the function, its parameters, return value, and all fields

Applied to files:

  • examples/todo-with-auth0/apps/backend/src/utils/data-operations/define-operations.ts
📚 Learning: 2025-11-24T19:44:33.959Z
Learnt from: CR
Repo: halfdomelabs/baseplate PR: 0
File: examples/blog-with-auth/CLAUDE.md:0-0
Timestamp: 2025-11-24T19:44:33.959Z
Learning: Applies to examples/blog-with-auth/**/*.{ts,tsx,js,jsx} : Add JSDocs to all exported functions, interfaces, and classes with documentation of the function, its parameters, return value, and all fields

Applied to files:

  • examples/blog-with-auth/apps/backend/src/utils/data-operations/define-operations.ts
🧬 Code graph analysis (2)
examples/todo-with-auth0/apps/backend/src/utils/data-operations/define-operations.ts (1)
packages/fastify-generators/src/generators/core/service-context/templates/src/utils/service-context.ts (1)
  • ServiceContext (3-5)
packages/fastify-generators/src/generators/prisma/data-utils/templates/src/utils/data-operations/define-operations.ts (1)
packages/fastify-generators/src/generators/core/service-context/templates/src/utils/service-context.ts (1)
  • ServiceContext (3-5)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Verify Sync (blog-with-auth)
  • GitHub Check: Verify Sync (todo-with-auth0)
  • GitHub Check: test
  • GitHub Check: Test E2E
  • GitHub Check: Lint
🔇 Additional comments (12)
.changeset/lemon-swans-sink.md (1)

1-5: Verify that this is a patch release and not a breaking change.

Adding a required serviceContext parameter to the create, update, and delete function signatures in CreateOperationConfig, UpdateOperationConfig, and DeleteOperationConfig appears to be a breaking API change. Existing implementations would need to be updated to accept this new parameter. According to semantic versioning, breaking changes should warrant a major version bump, not a patch release.

examples/todo-with-auth0/apps/backend/src/utils/data-operations/define-operations.ts (9)

309-321: LGTM! Service context parameter added to create operation config.

The serviceContext parameter is properly typed and positioned in the function signature, enabling access to user context during create operations.


379-406: LGTM! Documentation example updated to demonstrate serviceContext usage.

The JSDoc example correctly demonstrates how to use serviceContext to populate audit fields like createdById, showing the practical value of this change.


498-507: LGTM! Implementation correctly forwards serviceContext.

The serviceContext parameter is properly threaded through to the config.create call, enabling downstream usage of user context in create operations.


586-599: LGTM! Service context parameter added to update operation config.

Consistent with the create operation changes, the serviceContext parameter enables access to user context during update operations.


661-690: LGTM! Documentation example demonstrates update audit tracking.

The JSDoc example shows how to use serviceContext to populate updatedById, enabling proper audit trail tracking for update operations.


808-818: LGTM! Implementation correctly forwards serviceContext.

The update operation implementation properly threads serviceContext through to the config.update call.


872-884: LGTM! Service context parameter added to delete operation config.

Completing the pattern, the serviceContext parameter enables access to user context during delete operations, which can be useful for authorization checks and lifecycle hooks.


924-952: LGTM! Documentation example updated for delete operation.

The JSDoc example correctly shows the serviceContext parameter in the function signature. While delete operations typically don't populate audit fields, having access to the context is valuable for authorization checks and lifecycle hooks.


1014-1023: LGTM! Implementation correctly forwards serviceContext.

The delete operation implementation properly threads serviceContext through to the config.delete call, completing the consistent pattern across all CRUD operations.

examples/blog-with-auth/apps/backend/src/utils/data-operations/define-operations.ts (1)

309-321: LGTM! Service context threading implemented consistently.

All changes in this file mirror the patterns in the todo-with-auth0 example and are correctly implemented:

  • serviceContext parameter added to all operation config interfaces (create, update, delete)
  • Implementation functions properly forward the context to operation callbacks
  • Documentation examples demonstrate practical usage for audit tracking

The consistency across example projects ensures a uniform developer experience.

Also applies to: 379-406, 498-507, 586-599, 661-690, 808-818, 872-884, 924-952, 1014-1023

packages/fastify-generators/src/generators/prisma/data-utils/templates/src/utils/data-operations/define-operations.ts (1)

307-319: LGTM! Code generator template updated consistently.

The template file correctly implements the serviceContext threading pattern:

  • All operation config interfaces updated with the new parameter
  • Implementation functions properly forward the context
  • Documentation examples demonstrate usage
  • Template placeholders (e.g., %serviceContextImports, $types) are correctly positioned

This template will generate code consistent with the manually updated example projects.

Also applies to: 377-404, 498-505, 584-597, 659-688, 808-816, 870-882, 922-950, 1014-1021


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kingston kingston merged commit 5d4ae05 into main Nov 26, 2025
17 checks passed
@kingston kingston deleted the kingston/eng-917-pass-service-context-to-create-update-operations branch November 26, 2025 01:36
@github-actions github-actions Bot mentioned this pull request Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant