
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
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.
deleteUnusedM2OItems
Used 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",
},
});
});
deleteUnusedM2AItems
Used 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â
preventDeletingM2AItems
Used 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_collection
goes 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â
replaceDeletedUserReferences
This 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);
});
resetFieldsHiddenByOption
Set 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"],
},
],
});
});
setProjectSettingsFromEnvVars
Used 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 6 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
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.