Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { createColumnDecoratorFactory } from "@fullstack-one/db";
// tslint:disable-next-line:variable-name
export const Files = createColumnDecoratorFactory({
getDirective: (inputTypes?: string[]) => {
const types = getTypes(inputTypes);
return `@files(types: [${types.map((type) => `"${type}"`).join(",")}])`;
},
getColumnOptions: () => ({ type: "jsonb", gqlType: "[BucketFile]", nullable: true }),
getExtension: (inputTypes: string[]) => {
const types = getTypes(inputTypes);
return ["files", types];
}
});
function getTypes(inputTypes?: string[]): string[] {
return inputTypes == null ? ["DEFAULT"] : inputTypes;
}
import { createColumnDecoratorFactory } from "@fullstack-one/db";
import { IPermission, IExpressionInput, IMutationViewsByName } from "./gql-schema-builder/interfaces";
interface IOptions {
name: string;
params?: TParams;
gqlType: string;
}
// tslint:disable-next-line:variable-name
export const Computed = createColumnDecoratorFactory({
getDirective: ({ name, params }) => {
if (params == null) return `@computed(expression: "${name}")`;
return `@computed(expression: "${name}", params: ${JSON.stringify(params)})`;
},
getColumnOptions: ({ gqlType }) => ({ gqlType })
});
// tslint:disable-next-line:function-name
export function QueryPermissions(readExpressions: IExpressionInput) {
return (target: object, columnName: string): void => {
const entityName = target.constructor.name;
addQueryPermissions(entityName, columnName, readExpressions);
};
}
interface IMutationPermissions {
export function Computed(options: IOptions) {
const directiveDecorator = createColumnDecoratorFactory({
getDirective: ({ name, params }) => {
if (params == null) return `@computed(expression: "${name}")`;
return `@computed(expression: "${name}", params: ${JSON.stringify(params)})`;
},
getColumnOptions: ({ gqlType }) => ({ gqlType })
})(options);
return (target: any, columnName: string): void => {
directiveDecorator(target, columnName);
const tableName = target.constructor.name;
const afterLoadFnName = `${resolveComputedColumnPrefix}${columnName}`;
target.constructor[afterLoadFnName] = (entity: IObjectLiteral, connection: Connection) => {
if (entity[columnName] == null) {
entity[columnName] = async () => {
const expressionCompiler = new ExpressionCompiler(expressions, "_local_table_", true);