Skip to content

feat(sdk): added support for bulk operations on entities#143

Merged
danshw merged 2 commits intomainfrom
entities_bulk_update
Mar 16, 2026
Merged

feat(sdk): added support for bulk operations on entities#143
danshw merged 2 commits intomainfrom
entities_bulk_update

Conversation

@danshw
Copy link
Contributor

@danshw danshw commented Mar 15, 2026

No description provided.

@claude
Copy link

claude bot commented Mar 15, 2026

Claude finished @danshw's task —— View job


PR Review: Bulk Operations Support

I've reviewed the implementation of bulk operations for entities. Here's my comprehensive feedback:

✅ Code Quality and Best Practices

  • Consistent API Design: The bulk operations follow the existing patterns in the codebase with clear method signatures and parameter types
  • Type Safety: Proper TypeScript types are defined for all new methods and their return values
  • Code Organization: Changes are well-organized across appropriate files (types, implementation, and tests)

🐛 Potential Issues

  1. Missing Test for bulkCreate: While the PR adds the bulkCreate method implementation in src/modules/entities.ts:160-162, there is no corresponding test for this endpoint in the test file. This is a test coverage gap.

  2. Inconsistent HTTP Methods: The bulkUpdate method uses PUT (axios.put) while updateMany uses PATCH (axios.patch). This is correct based on REST conventions (PUT for full resource updates, PATCH for partial updates), but worth documenting the distinction.

⚡ Performance Considerations

  1. No Batch Size Limits: Neither bulkCreate nor bulkUpdate appear to have any client-side validation for array size limits. Consider:

    • Adding a reasonable limit or warning for very large arrays
    • Documenting any server-side limits in the JSDoc comments
    • Consider chunking for very large datasets
  2. Batching Pattern: The updateMany operation already implements a batching pattern with has_more flag. Consider whether bulkCreate and bulkUpdate might benefit from similar patterns for large datasets.

🔒 Security Concerns

  1. Input Validation: No client-side validation is performed on the bulk operation payloads. While server-side validation is expected, consider:

    • Validating that the array is not empty
    • Ensuring each object in bulkUpdate has a valid id field
    • Checking for duplicate IDs in bulkUpdate requests
  2. Rate Limiting: Bulk operations can potentially create/update many records at once. Ensure the server has appropriate rate limiting to prevent abuse.

📋 Test Coverage

Good coverage for:

  • updateMany with proper test cases including the has_more scenario
  • bulkUpdate with multiple update scenarios

Missing coverage for:

  • bulkCreate - No test case exists
  • Edge cases like empty arrays, malformed data, or server errors
  • Very large batch operations

📝 Recommendations

  1. Add test for bulkCreate:
test("bulkCreate() should create multiple entities", async () => {
  const newTodos = [
    { title: "Task 1", completed: false },
    { title: "Task 2", completed: false },
  ];
  const createdTodos: Todo[] = [
    { id: "1", title: "Task 1", completed: false },
    { id: "2", title: "Task 2", completed: false },
  ];

  scope
    .post(`/api/apps/${appId}/entities/Todo/bulk`, newTodos)
    .reply(201, createdTodos);

  const result = await base44.entities.Todo.bulkCreate(newTodos);
  
  expect(result).toHaveLength(2);
  expect(result[0].title).toBe("Task 1");
  expect(scope.isDone()).toBe(true);
});
  1. Add input validation for bulk operations
  2. Document any size limits in JSDoc comments
  3. Consider error handling tests for partial failures in bulk operations

✅ Summary

The implementation is clean and follows existing patterns well. The main concern is the missing test coverage for bulkCreate. Once that's addressed and the other minor suggestions are considered, this will be a solid addition to the SDK.

@github-actions
Copy link

github-actions bot commented Mar 15, 2026

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/sdk@0.8.20-pr.143.76a314c

Prefer not to change any import paths? Install using npm alias so your code still imports @base44/sdk:

npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.20-pr.143.76a314c"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "@base44/sdk": "npm:@base44-preview/sdk@0.8.20-pr.143.76a314c"
  }
}

Preview published to npm registry — try new features instantly!

@claude
Copy link

claude bot commented Mar 15, 2026

Claude finished @danshw's task —— View job


PR Review: Bulk Operations Support Update

I've reviewed the updated implementation of bulk operations for entities. The previous review feedback has been addressed with documentation improvements. Here's my updated assessment:

✅ Code Quality and Best Practices

  • Excellent API Design: The bulk operations follow consistent patterns with clear method signatures
  • Strong Type Safety: Proper TypeScript types are defined for all methods and return values
  • Well-Documented: The latest commit improved documentation clarity, especially for updateMany supporting multiple MongoDB operators

🐛 Potential Issues

Critical: Missing Test Coverage for bulkCreate
The bulkCreate method (src/modules/entities.ts:160-162) still lacks test coverage. This is a significant gap that should be addressed before merging:

// Missing test case in tests/unit/entities.test.ts
test("bulkCreate() should create multiple entities", async () => {
  const newTodos = [
    { title: "Task 1", completed: false },
    { title: "Task 2", completed: false },
  ];
  const createdTodos: Todo[] = [
    { id: "1", title: "Task 1", completed: false },
    { id: "2", title: "Task 2", completed: false },
  ];

  scope
    .post(`/api/apps/${appId}/entities/Todo/bulk`, newTodos)
    .reply(201, createdTodos);

  const result = await base44.entities.Todo.bulkCreate(newTodos);
  
  expect(result).toHaveLength(2);
  expect(result[0].title).toBe("Task 1");
  expect(scope.isDone()).toBe(true);
});

⚡ Performance Considerations

  1. Batch Size Limits: The documentation now correctly states:

    • bulkUpdate: Maximum 500 items per request
    • updateMany: Batches up to 500 records at a time
    • bulkCreate: No documented limit (should be clarified)
  2. Missing Error Handling: Consider how partial failures are handled:

    • What happens if some records in bulkCreate fail validation?
    • How are errors reported when bulkUpdate partially fails?

🔒 Security Concerns

  1. Input Validation: No client-side validation for:

    • Empty arrays (could cause unnecessary API calls)
    • Duplicate IDs in bulkUpdate requests
    • Maximum array size for bulkCreate
  2. MongoDB Operator Safety: The updateMany method now supports multiple operators, which increases flexibility but also potential for misuse. Ensure server-side validation prevents dangerous operations.

📋 Test Coverage

Good coverage:

  • updateMany with single and multiple operators
  • bulkUpdate with multiple update scenarios
  • ✅ Proper batching behavior (has_more flag)

Missing coverage:

  • bulkCreate - No test exists
  • ❌ Error scenarios (empty arrays, invalid data, server errors)
  • ❌ Edge cases (maximum batch sizes, partial failures)

📝 Documentation Improvements (Latest Commit)

The recent commit improved documentation clarity:

  • ✅ Clarified updateMany supports multiple MongoDB operators
  • ✅ Added constraint that each field may only appear in one operator
  • ✅ Specified 500 item batch size for both updateMany and bulkUpdate
  • ✅ Updated examples to show multiple operators usage

🎯 Recommendations

  1. Priority 1: Add test for bulkCreate before merging
  2. Priority 2: Document the maximum batch size for bulkCreate
  3. Priority 3: Add tests for error scenarios and edge cases
  4. Consider: Adding client-side validation for common issues (empty arrays, duplicate IDs)

✅ Summary

The implementation is well-designed and the documentation improvements in the latest commit are helpful. However, the missing test coverage for bulkCreate remains a blocker. Once that's addressed, this will be a solid addition to the SDK.

@github-actions github-actions bot added the docs-draft PR has auto-drafted documentation suggestions label Mar 15, 2026
@danshw danshw merged commit bd816ff into main Mar 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-draft PR has auto-drafted documentation suggestions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants