ramda#pipe TypeScript Examples

The following examples show how to use ramda#pipe. 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 6 votes vote down vote up
applyHooks = <T>(
  chain: Hook<T>[],
  src: T | undefined,
  lines: string[]
): string[] => {
  const boundChain = chain.map((f) => (l) => f(l, src));
  // @ts-ignore
  return pipe(...boundChain)(lines);
}
Example #2
Source File: utils.ts    From notabug with MIT License 6 votes vote down vote up
listingNodeToIds = ifElse(
  x => !!x,
  pipe<GunNode, GunNode, readonly string[]>(
    unpackNode,
    Listing.ListingNode.ids
  ),
  always([])
)
Example #3
Source File: utils.ts    From notabug with MIT License 6 votes vote down vote up
listingNodesToIds = pipe<
  readonly GunNode[],
  ReadonlyArray<readonly string[]>,
  readonly string[]
>(
  map(listingNodeToIds),
  reduce<readonly string[], readonly string[]>(union, [])
)
Example #4
Source File: overrides.ts    From the-fake-backend with ISC License 6 votes vote down vote up
/**
   * Get routes with overrides.
   *
   * @return An array containing all the routes with overrides
   */
  getAll() {
    return this.routeManager
      .getAll()
      .filter(
        pipe(propOr([], 'methods'), filterOverridableMethods, isNotEmpty)
      );
  }
Example #5
Source File: useNextQuestion.tsx    From nosgestesclimat-site with MIT License 5 votes vote down vote up
questionDifference = (rule1 = '', rule2 = '') =>
	1 /
	(1 +
		pipe(
			zipWith(equals),
			takeWhile(Boolean),
			length
		)(rule1.split(' . '), rule2.split(' . ')))
Example #6
Source File: serializeSimulation.ts    From nosgestesclimat-site with MIT License 5 votes vote down vote up
serialize = pipe(currentSimulationSelector, JSON.stringify)
Example #7
Source File: SaiditIngestStore.ts    From notabug with MIT License 5 votes vote down vote up
getListingThings = pipe(
  pathOr<readonly any[]>([], ['data', 'children']),
  map(item => ({
    ...item.data,
    kind: item.kind
  })),
  filter(d => !!d)
)
Example #8
Source File: overrides.ts    From the-fake-backend with ISC License 5 votes vote down vote up
function getOverridableRoutesMethodsTypesNames(route: Route) {
  return filterOverridableMethods(route.methods).map(
    pipe(prop('type'), formatMethodType)
  );
}
Example #9
Source File: generateModelFile.ts    From kanel with MIT License 4 votes vote down vote up
generateModelFile = (
  model: TableModel | ViewModel,
  {
    typeMap,
    userTypes,
    schemaName,
    nominators,
    externalTypesFolder,
    schemaFolderMap,
    makeIdType,
  }: {
    typeMap: TypeMap;
    userTypes: (string | any)[];
    schemaName: string;
    nominators: Nominators;
    externalTypesFolder?: string;
    schemaFolderMap: { [schemaName: string]: string };
    makeIdType: (innerType: string, modelName: string) => string;
  }
): string[] => {
  const fileNominator = nominators.fileNominator;
  const makeIdName = (name) =>
    nominators.idNominator(nominators.modelNominator(name), name);

  const lines = [];
  const { comment, tags } = model;

  const importGenerator = new ImportGenerator(schemaFolderMap[schemaName]);
  const referencedIdTypes = pipe(
    filter((p: Column) => Boolean(p.reference)),
    map((p) => p.reference),
    reject((p: Reference) => p.schema === schemaName && p.table === model.name),
    uniq
  )(model.columns);
  referencedIdTypes.forEach((i) => {
    const givenName = nominators.modelNominator(i.table);
    importGenerator.addImport(
      makeIdName(i.table),
      false,
      path.join(schemaFolderMap[i.schema], fileNominator(givenName, i.table)),
      false
    );
  });
  const cols = map(
    ({ isArray, type, subType, ...rest }) => ({
      type: isArray ? subType : type,
      ...rest,
    }),
    model.columns
  );
  const appliedUserTypes = uniq(
    map(
      (p: Column | { type: string }) => p.type,
      filter((p) => userTypes.indexOf(p.type) !== -1, cols)
    )
  );
  appliedUserTypes.forEach((t) => {
    const givenName = nominators.typeNominator(t);
    importGenerator.addImport(
      givenName,
      true,
      path.join(schemaFolderMap[schemaName], fileNominator(givenName, t)),
      false
    );
  });

  const overriddenTypes = map(
    (p: Column) => p.tags.type as string,
    filter((p) => Boolean(p.tags.type), model.columns)
  );
  forEach((importedType) => {
    const givenName = importedType; // We expect people to have used proper casing in their comments
    importGenerator.addImport(
      givenName,
      true,
      path.join(externalTypesFolder, fileNominator(givenName, importedType)),
      false
    );
  }, overriddenTypes);

  const primaryColumns = filter((c) => c.isPrimary, model.columns);

  // If there's one and only one primary key, that's the identifier.
  const hasIdentifier = primaryColumns.length === 1;

  const properties = model.columns.map((c) => {
    const isIdentifier = hasIdentifier && c.isPrimary;
    const idType = isIdentifier && makeIdName(model.name);
    const referenceType = c.reference && makeIdName(c.reference.table);
    let rawType = c.tags.type || idType || referenceType || typeMap[c.type];
    if (typeof rawType === 'boolean') {
      throw new Error('@type tag must include the actual type: "@type:string"');
    }
    if (typeof rawType === 'object') {
      importGenerator.addImport(
        rawType.name,
        rawType.defaultImport,
        rawType.absoluteImport
          ? rawType.module
          : path.join(
              externalTypesFolder || schemaFolderMap[schemaName],
              rawType.module
            ),
        rawType.absoluteImport
      );
      rawType = rawType.name;
    }
    if (!rawType) {
      console.warn(`Unrecognized type: '${c.type}'`);
      rawType = nominators.typeNominator(c.type);
    }
    const typeName = c.nullable ? `${rawType} | null` : rawType;
    const modelAttributes = {
      commentLines: c.comment ? [c.comment] : [],
      optional: false,
    };
    const initializerAttributes = {
      omit: c.generated === 'ALWAYS',
      commentLines: c.comment ? [c.comment] : [],
      optional: c.defaultValue || c.nullable,
    };

    if (c.defaultValue) {
      initializerAttributes.commentLines.push(
        `Default value: ${c.defaultValue}`
      );
    }

    c.indices.forEach((index) => {
      const commentLine = index.isPrimary
        ? `Primary key. Index: ${index.name}`
        : `Index: ${index.name}`;
      modelAttributes.commentLines.push(commentLine);
      initializerAttributes.commentLines.push(commentLine);
    });

    return {
      name: nominators.propertyNominator(c.name, model),
      optional: false,
      typeName,
      modelAttributes,
      initializerAttributes,
    };
  });

  const importLines = importGenerator.generateLines();
  lines.push(...importLines);

  if (importLines.length) {
    lines.push('');
  }

  if (hasIdentifier) {
    const [{ type, tags }] = primaryColumns;

    const innerType = (tags.type ||
      typeMap[type] ||
      nominators.typeNominator(type)) as string;

    lines.push(
      `export type ${makeIdName(model.name)} = ${makeIdType(
        innerType,
        model.name
      )}`
    );
    lines.push('');
  }

  const givenName = nominators.modelNominator(model.name);

  const interfaceLines = generateInterface({
    name: givenName,
    properties: properties.map(({ modelAttributes, ...props }) => ({
      ...props,
      ...modelAttributes,
    })),
    comment,
    exportAsDefault: true,
  });
  lines.push(...interfaceLines);

  const generateInitializer = !tags['fixed'] && model.type === 'table';
  if (generateInitializer) {
    lines.push('');
    const initializerInterfaceLines = generateInterface({
      name: nominators.initializerNominator(givenName, model.name),
      properties: properties
        .filter((p) => !p.initializerAttributes.omit)
        .map(({ initializerAttributes, ...props }) => ({
          ...props,
          ...initializerAttributes,
        })),
      comment,
      exportAsDefault: false,
    });
    lines.push(...initializerInterfaceLines);
  }
  return lines;
}