ramda#pluck TypeScript Examples

The following examples show how to use ramda#pluck. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: processSchema.ts    From kanel with MIT License 4 votes vote down vote up
processSchema = async (
  schemaConfig: SchemaConfig,
  schema: Schema,
  typeMap: TypeMap,
  nominators: Nominators,
  modelProcessChain: Hook<Model>[],
  typeProcessChain: Hook<Type>[],
  schemaFolderMap: { [schemaName: string]: string },
  makeIdType: (innerType: string, modelName: string) => string
) => {
  const { tables, views, types } = schema;

  const { compositeTypes, enumTypes } = getSupportedTypes(types);

  enumTypes.forEach((t) => {
    const typeFileLines = generateTypeFile(t, nominators.typeNominator);
    const wetTypeFileLines = applyHooks(typeProcessChain, t, typeFileLines);
    const givenName = nominators.typeNominator(t.name);
    const filename = `${nominators.fileNominator(givenName, t.name)}.ts`;
    writeFile({
      fullPath: path.join(schemaConfig.modelFolder, filename),
      lines: wetTypeFileLines,
    });
  });

  const models = [
    ...tables.map((t) => ({ ...t, type: 'table' } as const)),
    ...views.map((t) => ({ ...t, type: 'view' } as const)),
  ];

  const rejectIgnored = reject((m: { name: string }) =>
    (schemaConfig.ignore || []).some((matcher) => isMatch(m.name, matcher))
  );
  const includedModels = rejectIgnored(models);

  const userTypes = pluck('name', types);
  const tableOrViewTypes = pluck('name', includedModels);

  compositeTypes.forEach((t) => {
    const typeFileLines = generateCompositeTypeFile(t, {
      typeMap,
      userTypes,
      tableOrViewTypes,
      nominators,
      schemaName: schemaConfig.name,
      externalTypesFolder: schemaConfig.externalTypesFolder,
      schemaFolderMap,
    });
    const wetTypeFileLines = applyHooks(typeProcessChain, t, typeFileLines);
    const filename = `${nominators.fileNominator(
      nominators.typeNominator(t.name),
      t.name
    )}.ts`;
    writeFile({
      fullPath: path.join(schemaConfig.modelFolder, filename),
      lines: wetTypeFileLines,
    });
  });

  includedModels.forEach((m) => {
    const modelFileLines = generateModelFile(m, {
      typeMap,
      userTypes,
      nominators,
      schemaName: schemaConfig.name,
      externalTypesFolder: schemaConfig.externalTypesFolder,
      schemaFolderMap,
      makeIdType,
    });
    const wetModelFileLines = applyHooks(modelProcessChain, m, modelFileLines);
    const filename = `${nominators.fileNominator(
      nominators.modelNominator(m.name),
      m.name
    )}.ts`;
    writeFile({
      fullPath: path.join(schemaConfig.modelFolder, filename),
      lines: wetModelFileLines,
    });
  });

  const indexFileLines = generateIndexFile(
    includedModels,
    userTypes,
    nominators
  );
  const wetIndexFileLines = applyHooks(
    modelProcessChain,
    undefined,
    indexFileLines
  );
  writeFile({
    fullPath: path.join(schemaConfig.modelFolder, 'index.ts'),
    lines: wetIndexFileLines,
  });
}