kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Migrate all plugins and shared packages to the new Resource-layer methods

Open AlexVelezLl opened this issue 4 months ago • 2 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Tracking issue for migrating all Kolibri plugin code from the old resource-layer methods to the new, simpler ones added in #15056. Once every plugin has been moved over, a later issue can safely remove the old methods. This issue holds the shared migration recipe; the actual work is split into one task per plugin.

Scope

In scope — migrate each of these to the new methods (one child task each):

  • coach
  • device
  • facility
  • learn
  • policies
  • setup_wizard
  • user_auth
  • user_profile
  • packages/kolibri
  • packages/kolibri-common

Out of scope (handled in other issues):

  • Adding the new methods (done in #15056).
  • Removing the old methods and cache-management helpers.
  • Recovering _v2 custom method names back to their originals.
  • Moving scattered client calls into resources.
  • Cross-package type inference improvements.

Strategy

Every child task applies the same recipe to one plugin/package. All of this is additive-safe: the new methods already exist (#15056) and the old ones still work until a later removal issue.

1. Replace old base-method calls with the new ones:

Old New
fetchModel retrieve
fetchCollection list
createModel create
saveModel (new object) create
saveModel (existing object) update/useUpdate* (se below)
deleteModel delete
saveCollection bulkCreate
deleteCollection bulkDelete
raw get / list / create retrieve / list / create
fetchDetailModel, fetchDetailCollection, fetchListCollection, getListEndpoint, postDetailEndpoint, postListEndpoint, accessDetailEndpoint, accessListEndpoint the new request primitive (via retrieve/list shaping, or the custom method's own request call)

2. Remove cache-management calls that no longer mean anything: clearCache, getModel, getCollection, addModel, findModel, removeModel, removeCollection, unCacheModel, unCacheCollection.

3. For custom methods the plugin/package uses:

  • If the custom method's Resource is defined and used only within this same plugin, rewrite the method to build on the new request primitive.
  • If the custom method is on a shared resource (used by more than one plugin/package — e.g. resources in kolibri-common), add a parallel method with a _v2 suffix (e.g. createuseronremote → createuseronremote_v2) that uses request, and point this plugin at the _v2 name. Leave the original method in place so other not-yet-migrated consumers keep working.
  • _v2 methods will be removed in a future issue, so please do not leave any unnecessary comments about the method it will replace (flagging differences, etc), because we will remove them anyway.

4. Reactive reads should use the useRetrieve / useList composables where applicable; if it will become a large refactor, then omit it.

5. Updates

  • The new update method introduced a difference: Now it does not compute the payload diff automatically; instead, it receives a baseline object to compute the diff. This means now it's the consumer's responsibility to keep a snapshot of the object being updated.
    • For simple updates like a toggle switch, this is not relevant, but for patches of large objects we will need to store the `baseline.
    • For these large objects, we should migrate the code to use the Resource.useUpdate composable instead; this composable abstracts the baseline snapshots and sends the baseline properly to the update method.

5. Preferences

  • For new methods, always prefer async/await, no matter if all other methods in the same class/module use callbacks.
  • New methods for custom actions should use arg/param names consistent with the new Resource API. (e.g. params instead of getParams even if the method being replaced uses getParams)

Testing Requirements

Migration is behavior-preserving. Each child task should keep the plugin/package's existing tests passing (pnpm test-jest), with no change to runtime behavior — only the resource methods being called change. Also check for tests that call or mock the replaced methods (e.g. mocking fetchModel, fetchCollection, clearCache) and update them to use/mock the new methods accordingly.

Acceptance Criteria

  • [ ] Every plugin/package in Scope has a completed migration task.
  • [ ] No in-scope code calls the old base methods or cache-management helpers.
  • [ ] Shared-resource custom methods used by migrated code exist in _v2 form; originals remain for not-yet-migrated consumers.
  • [ ] Existing tests pass across all migrated plugins/packages.

AI usage

I used Claude Code to help draft this tracking issue, and its migration recipe from my notes on the resource-layer refactor plan. I reviewed and edited the content and confirmed the scope and plugin list myself.

AlexVelezLl avatar Jul 23 '26 14:07 AlexVelezLl

Watching for resolution on behalf of learningequality/kolibri#15061.

rtibblesbot avatar Aug 04 '26 14:08 rtibblesbot

All subissues are already closed.

AlexVelezLl avatar Aug 31 '26 13:08 AlexVelezLl