Skip to content

Conversation

@koxudaxi
Copy link
Collaborator

@koxudaxi koxudaxi commented Dec 10, 2025

TL;DR

Added a new FunctionService class to manage function registration, versioning, and retrieval.

What changed?

Created a new file cloud/db/services/functions.ts that implements a FunctionService class with the following capabilities:

  • registerOrGet: Registers a new function or retrieves an existing one, with automatic versioning logic
  • getEnvironmentContext: Retrieves environment, project, and organization context
  • getByHash: Retrieves a function by its hash within an environment
  • getById: Retrieves a function by its ID
  • list: Lists functions with filtering options for name, tags, and pagination

The service handles versioning automatically by:

  • Starting at version 1.0 for new functions
  • Incrementing the major version when the function signature changes
  • Incrementing the minor version when only the implementation changes

How to test?

  1. Create a new function using the registerOrGet method:

    const functionService = new FunctionService(db);
    const result = await Effect.runPromise(
      functionService.registerOrGet({
        code: "function example() { return 'hello'; }",
        hash: "abc123",
        signature: "function example(): string",
        signatureHash: "def456",
        name: "example"
      }, { environmentId: "env_123", projectId: "proj_456", organizationId: "org_789" })
    );
  2. Retrieve a function by hash:

    const func = await Effect.runPromise(
      functionService.getByHash("abc123", "env_123")
    );
  3. Test versioning by registering the same function with different implementations.

Why make this change?

This service provides a structured way to manage function registration with proper versioning semantics. It ensures that:

  1. Functions are uniquely identified by their hash within an environment
  2. Version numbers follow semantic versioning principles based on signature changes
  3. Race conditions are handled properly using database transactions
  4. Functions can be easily queried with various filters

The implementation uses Effect.js for error handling and provides clear error types for different failure scenarios.

This was referenced Dec 10, 2025
@koxudaxi koxudaxi force-pushed the 12-10-feat_db_add_functions_schema_and_migration branch from 0da1a5d to 6af4a16 Compare January 5, 2026 09:48
@koxudaxi koxudaxi force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch 2 times, most recently from 9bd8cf8 to 62d47af Compare January 5, 2026 10:01
@koxudaxi koxudaxi force-pushed the 12-10-feat_db_add_functions_schema_and_migration branch from 6af4a16 to eca6691 Compare January 5, 2026 14:15
@koxudaxi koxudaxi force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch from 62d47af to b8d82c0 Compare January 5, 2026 14:16
@koxudaxi koxudaxi force-pushed the 12-10-feat_db_add_functions_schema_and_migration branch from eca6691 to be37dd1 Compare January 5, 2026 14:32
@koxudaxi koxudaxi force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch from b8d82c0 to b2aca9e Compare January 5, 2026 14:32
@willbakst willbakst force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch from b2aca9e to 85c86f3 Compare January 6, 2026 00:04
@willbakst willbakst force-pushed the 12-10-feat_db_add_functions_schema_and_migration branch from be37dd1 to 154a7a8 Compare January 6, 2026 00:04
@willbakst willbakst force-pushed the 12-10-feat_db_add_functions_schema_and_migration branch from 154a7a8 to b142be9 Compare January 6, 2026 00:23
@willbakst willbakst force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch from 85c86f3 to 0e3d42a Compare January 6, 2026 00:23
@koxudaxi koxudaxi force-pushed the 12-10-feat_db_add_functions_schema_and_migration branch from b142be9 to 379c74a Compare January 6, 2026 00:30
@koxudaxi koxudaxi force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch from 0e3d42a to 76bc724 Compare January 6, 2026 00:30
@willbakst willbakst force-pushed the 12-10-feat_db_add_functions_schema_and_migration branch 2 times, most recently from 48b4b12 to 5f15f42 Compare January 6, 2026 02:16
@willbakst willbakst force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch from 76bc724 to b41aa73 Compare January 6, 2026 02:16
@willbakst willbakst force-pushed the 12-10-feat_db_add_functions_schema_and_migration branch from 5f15f42 to 965b130 Compare January 6, 2026 02:26
@willbakst willbakst force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch 2 times, most recently from 6127227 to 47bc1a5 Compare January 6, 2026 02:46
@willbakst willbakst force-pushed the 12-10-feat_db_add_functions_schema_and_migration branch from 965b130 to fce5987 Compare January 6, 2026 02:46
@willbakst willbakst changed the base branch from 12-10-feat_db_add_functions_schema_and_migration to graphite-base/1624 January 6, 2026 02:50
@willbakst willbakst force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch from 47bc1a5 to 98dc5cc Compare January 6, 2026 02:51
@graphite-app graphite-app bot changed the base branch from graphite-base/1624 to v2 January 6, 2026 02:51
@willbakst willbakst force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch from 98dc5cc to 76402ed Compare January 6, 2026 02:52
- Add ImmutableResourceError to errors.ts for immutable resources
- Add ImmutableResourceError to BaseAuthenticatedEffectService update method
- Refactor Functions service: getByHash → findByHash, simplified CRUD pattern
- Update create to fail with AlreadyExistsError on duplicate hash
- Update update to return ImmutableResourceError (functions are immutable)
- Update tests to match new API
@willbakst willbakst force-pushed the 12-10-feat_db_add_functionservice_for_function_versioning branch from 76402ed to 445c6d1 Compare January 6, 2026 02:52
@willbakst willbakst merged commit 0a4e907 into v2 Jan 6, 2026
10 checks passed
Copy link
Collaborator

Merge activity

@willbakst willbakst deleted the 12-10-feat_db_add_functionservice_for_function_versioning branch January 6, 2026 02:57
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.

3 participants