How to use the @fullstack-one/db.createColumnDecoratorFactory function in @fullstack-one/db

To help you get started, we’ve selected a few @fullstack-one/db examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fullstack-build / fullstack-one / packages / file-storage / lib / decorators.ts View on Github external
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;
}
github fullstack-build / fullstack-one / packages / schema-builder / lib / decorators.ts View on Github external
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 {
github fullstack-build / fullstack-one / packages / schema-builder / lib / decorators / computedColumn.ts View on Github external
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);