mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
@@ -155,7 +155,7 @@ function registerHooks(hooks: Extension[]) {
|
||||
|
||||
const register = getModuleDefault(hookInstance);
|
||||
|
||||
const events = register({ services, exceptions, env, database: getDatabase(), getSchema });
|
||||
const events = register({ services, exceptions, env, database: getDatabase(), logger, getSchema });
|
||||
|
||||
for (const [event, handler] of Object.entries(events)) {
|
||||
if (event.startsWith('cron(')) {
|
||||
@@ -195,6 +195,6 @@ function registerEndpoints(endpoints: Extension[], router: Router) {
|
||||
const scopedRouter = express.Router();
|
||||
router.use(`/${pathName}`, scopedRouter);
|
||||
|
||||
register(scopedRouter, { services, exceptions, env, database: getDatabase(), getSchema });
|
||||
register(scopedRouter, { services, exceptions, env, database: getDatabase(), logger, getSchema });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ListenerFn } from 'eventemitter2';
|
||||
import { Router } from 'express';
|
||||
import { Knex } from 'knex';
|
||||
import { Logger } from 'pino';
|
||||
import env from '../env';
|
||||
import * as exceptions from '../exceptions';
|
||||
import * as services from '../services';
|
||||
@@ -11,6 +12,7 @@ export type ExtensionContext = {
|
||||
exceptions: typeof exceptions;
|
||||
database: Knex;
|
||||
env: typeof env;
|
||||
logger: Logger;
|
||||
getSchema: typeof getSchema;
|
||||
};
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ that is scoped to `/<extension-name>`, while `context` holds the following prope
|
||||
- `database` — Knex instance that is connected to the current database.
|
||||
- `getSchema` — Async function that reads the full available schema for use in services
|
||||
- `env` — Parsed environment variables.
|
||||
- `logger` — [Pino](https://github.com/pinojs/pino) instance.
|
||||
|
||||
## 3. Restart the API
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@ The `registerHook` function receives a context parameter with the following prop
|
||||
- `database` — Knex instance that is connected to the current database
|
||||
- `getSchema` — Async function that reads the full available schema for use in services
|
||||
- `env` — Parsed environment variables
|
||||
- `logger` — [Pino](https://github.com/pinojs/pino) instance.
|
||||
|
||||
### Event Handler Function
|
||||
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -51264,6 +51264,7 @@
|
||||
"knex": "0.95.10",
|
||||
"knex-schema-inspector": "1.6.0",
|
||||
"lodash": "4.17.21",
|
||||
"pino": "6.13.1",
|
||||
"vue": "3.2.7",
|
||||
"vue-router": "4.0.11"
|
||||
},
|
||||
@@ -53405,6 +53406,7 @@
|
||||
"knex-schema-inspector": "1.6.0",
|
||||
"lodash": "4.17.21",
|
||||
"npm-run-all": "4.1.5",
|
||||
"pino": "6.13.1",
|
||||
"rimraf": "3.0.2",
|
||||
"typescript": "4.4.2",
|
||||
"vue": "3.2.7",
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
"knex": "0.95.10",
|
||||
"knex-schema-inspector": "1.6.0",
|
||||
"lodash": "4.17.21",
|
||||
"pino": "6.13.1",
|
||||
"vue": "3.2.7",
|
||||
"vue-router": "4.0.11"
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Logger } from 'pino';
|
||||
import {
|
||||
API_EXTENSION_PACKAGE_TYPES,
|
||||
API_EXTENSION_TYPES,
|
||||
@@ -65,5 +66,6 @@ export type ApiExtensionContext = {
|
||||
exceptions: any;
|
||||
database: Knex;
|
||||
env: Record<string, any>;
|
||||
logger: Logger;
|
||||
getSchema: (options?: { accountability?: Accountability; database?: Knex }) => Promise<Record<string, any>>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user