dbaas
Version:
Database as a service. Expose db to REST and GraphQL.
72 lines • 2.85 kB
JavaScript
import { InvalidConfigException, } from "directus";
import createItemsService from "./createItemsService.js";
// import getUserAccountability from "./getUserAccountability.js"
/** Services instance created per request or filter/action context */
class ServicesBase {
/** Global extension context */
/** The the context or request this services instance made for */
/** The ItemsService options */
/** The cached ItemsService scoped by request or hook context */
constructor(extensionContext, requestOrHookContext, options) {
this.
this.
this.
}
get extensionContext() {
return this.
}
get requestOrHookContext() {
return this.
}
get options() {
return this.
}
loginAsAdmin() {
if (Object.keys(this.
throw new InvalidConfigException("You cannot login after any ItemsService has been initialized");
}
// const accountability = await getUserAccountability(
// this.#requestOrHookContext,
// userId,
// )
// if (!accountability) {
// throw new InvalidCredentialsException("User not found")
// }
this.
...this.
accountability: {
// satisfy TypeScript
role: null,
...this.
// For now we can't login as any user/role to keep activity record.
// The accountability.permissions must be set based on the user/role
// There is an issue importing getPermissions or even fetch using knex directly.
admin: true,
},
};
}
/** Get and cache the ItemsService scoped by request or hook context */
getItemsService(collection) {
let itemsService = this.
if (!itemsService) {
const reqOrHookCtx = this.requestOrHookContext;
const options = this.options;
// This check is unnecessary in JS but just to satisfy TS
// against choosing the createItemsService overloads
if ("url" in reqOrHookCtx) {
itemsService = createItemsService(collection, reqOrHookCtx, options);
}
else {
itemsService = createItemsService(collection, reqOrHookCtx, options);
}
this.
}
return itemsService;
}
}
export default ServicesBase;
//# sourceMappingURL=ServicesBase.js.map