semver#rsort TypeScript Examples

The following examples show how to use semver#rsort. 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: TechInsightsDatabase.ts    From backstage with Apache License 2.0 6 votes vote down vote up
async getLatestSchemas(ids?: string[]): Promise<FactSchema[]> {
    const queryBuilder = this.db<RawDbFactSchemaRow>('fact_schemas');
    if (ids) {
      queryBuilder.whereIn('id', ids);
    }
    const existingSchemas = await queryBuilder.orderBy('id', 'desc').select();

    const groupedSchemas = groupBy(existingSchemas, 'id');
    return Object.values(groupedSchemas)
      .map(schemas => {
        const sorted = rsort(schemas.map(it => it.version));
        return schemas.find(it => it.version === sorted[0])!;
      })
      .map((it: RawDbFactSchemaRow) => ({
        ...omit(it, 'schema'),
        ...JSON.parse(it.schema),
        entityFilter: it.entityFilter ? JSON.parse(it.entityFilter) : null,
      }));
  }
Example #2
Source File: TechInsightsDatabase.ts    From backstage with Apache License 2.0 6 votes vote down vote up
private async getLatestSchema(id: string): Promise<RawDbFactSchemaRow> {
    const existingSchemas = await this.db<RawDbFactSchemaRow>('fact_schemas')
      .where({ id })
      .orderBy('id', 'desc')
      .select();
    if (existingSchemas.length < 1) {
      this.logger.warn(`No schema found for ${id}. `);
      throw new Error(`No schema found for ${id}. `);
    }
    const sorted = rsort(existingSchemas.map(it => it.version));
    return existingSchemas.find(it => it.version === sorted[0])!;
  }