How to use internal functions in Extensions?

We are trying to create a custom interface extension to handle m2a relations in a tree view style. so we have something like this:

  • headline
    • content
    • content
    • quiz
  • headline
    • content
    • headline
      • quiz
  • quiz

so we wanted to use built in list-m2a interface as boilerplate. but its dependent to many dependencies that are not available in pnpm packages.. like these:

import { usePageSize } from ‘@/composables/use-page-size’;
import { useRelationM2A } from ‘@/composables/use-relation-m2a’;
import { DisplayItem, RelationQueryMultiple, useRelationMultiple } from ‘@/composables/use-relation-multiple’;
import { useRelationPermissionsM2A } from ‘@/composables/use-relation-permissions’;
import { addRelatedPrimaryKeyToFields } from ‘@/utils/add-related-primary-key-to-fields’;
import { adjustFieldsForDisplays } from ‘@/utils/adjust-fields-for-displays’;

Available packages are listed here.

Is there any solution to use these without need to copy them? copying some is not an option because they have dependencies to not available packages too.

I recently proposed exporting Directus builtin modules, interfaces, layouts… at Discord, which would basically require to cut dependencies and export them along with Extension SDK.

@rijkvanzanten seemed to be open for that idea, so I hope we eventually will get there sometimes.

Hi @maazamaani :waving_hand: ! Welcome to the community.

Unfortunately, you are correct. A lot of those handy helpers and composables are not available through the @directus/extensions-sdk.

So the only way to build an extension using those the list-m2a interface as the boilerplate would be to copy them over into your extension code and install the missing dependencies (if / where available).

You can see examples of this approach in our directus-labs repository. Though we don’t have a boilerplate for the M2A interface.

It’s definitely not ideal :sad_but_relieved_face:, but it’s the current workaround until we can expose more of the internal API through the extensions SDK.

Hope that helps! Let me know if you have any other questions about building extensions.