
Security News
GitHub Actions Pricing Whiplash: Self-Hosted Actions Billing Change Postponed
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.
directus-hook-library
Advanced tools
A collection of customizable hooks for Directus. This is not an extension, but a library of scripts that could be used inside a Directus hook extension.
First create a Directus Extension and during setup choose the extension type hook.
Inside the extension folder install directus-hook-library:
npm install directus-hook-library
Import it in src/index.ts, like:
import { setProjectSettingsFromEnvVars } from "directus-hook-library";
Have a look at the examples below.
Tip: You can use multiple of these hook scripts inside the same Directus hook.
deleteUnusedM2OItemsUsed to delete related M2O items that loose their relation and should not be kept, which is not possible via directus itself. This makes sense for a M2O relation that is used like a O2O relation.
Delete all oneCollection items that loose their relationship to a manyCollections item.
(!) Important: You have to specify a (hidden) reverse relationship O2M in your oneCollection inside Directus to make this work.
// src/index.ts
import { defineHook } from "@directus/extensions-sdk";
import { deleteUnusedM2OItems } from "directus-hook-library";
export default defineHook((register, context) => {
deleteUnusedM2OItems(register, context, {
oneCollection: "meta_infos",
manyCollections: {
pages: "pages",
posts: "posts",
},
});
});
deleteUnusedM2AItemsUsed to delete related M2A items that loose their relation and should not be kept, which is not possible via directus itself.
Goes through all junctionCollections and stores the keys for each found anyCollection item. Then deletes all anyCollections items that are not included in the stored keys.
// src/index.ts
import { defineHook } from "@directus/extensions-sdk";
import {
toJunctionCollectionM2A,
toAnyCollectionM2A,
deleteUnusedM2AItems,
} from "directus-hook-library";
export default defineHook((register, context) => {
deleteUnusedM2AItems(register, context, {
anyCollections: [
"gallery",
"video",
"definition_list",
"related_content",
].map(toAnyCollectionM2A),
junctionCollections: ["page_editor_nodes", "post_editor_nodes"].map(
toJunctionCollectionM2A
),
});
});
toAnyCollectionM2A ... maps the array elements to objects of type AnyCollection with a default key field of “id”.
toJunctionCollectionM2A ... maps the array elements to objects of type JunctionCollection with a default foreignKey field of “item” and a default foreignCollection field of “collection”
preventDeletingM2AItemsUsed for M2A items to prevent their deletion, which is not possible via directus itself.
Goes through all junctionCollections and searches for the relatedCollection items to delete. If found, prevents deletion.
Find M2A items by searching the schema for
“one_allowed_collections”and look for collections that are deletable/reachable by the app/user (many_collectiongoes to thejunctionCollections)
// src/index.ts
import { defineHook } from "@directus/extensions-sdk";
import {
toJunctionCollectionM2A,
preventDeletingM2AItems,
} from "directus-hook-library";
export default defineHook((register, context) => {
preventDeletingM2AItems(register, context, {
relatedCollections: ["video"],
junctionCollections: ["page_editor_nodes", "post_editor_nodes"].map(
toJunctionCollectionM2A
),
});
});
toJunctionCollectionM2A ... maps the array elements to objects of type JunctionCollection with a default foreignKey field of “item” and a default foreignCollection field of “collection”
replaceDeletedUserReferencesThis replaces the reference to a deleted user with a reference to the current user in the directus_files collection.
// src/index.ts
import { defineHook } from "@directus/extensions-sdk";
import { replaceDeletedUserReferences } from "directus-hook-library";
export default defineHook((register, context) => {
replaceDeletedUserReferences(register, context);
});
resetFieldsHiddenByOptionSet fields to null that have a value but are hidden by a condition.
// src/index.ts
import { defineHook } from "@directus/extensions-sdk";
import { resetFieldsHiddenByOption } from "directus-hook-library";
export default defineHook((register, context) => {
resetFieldsHiddenByOption(register, context, {
collection: "conditional",
optionsField: "detail",
resetGroups: [
{
not: ["yes"],
nullify: ["title", "description"],
},
{
not: ["no"],
nullify: ["external_link"],
},
],
});
});
setProjectSettingsFromEnvVarsUsed for setting project settings from ENV vars like, PROJECT_URL.
This overwrites the values for settings in the Project Settings when starting Directus.
// src/index.ts
import { defineHook } from "@directus/extensions-sdk";
import { setProjectSettingsFromEnvVars } from "directus-hook-library";
export default defineHook((register, context) => {
setProjectSettingsFromEnvVars(register, context, [
"project_name",
"project_descriptor",
"project_url",
]);
});
For ENV variables like:
PROJECT_NAME=Directus
PROJECT_DESCRIPTOR=Hook
PROJECT_URL=http://localhost:3000
FAQs
A collection of customizable hooks for Directus
The npm package directus-hook-library receives a total of 0 weekly downloads. As such, directus-hook-library popularity was classified as not popular.
We found that directus-hook-library demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.