All files / app/model ext.ts

38.09% Statements 8/21
30.76% Branches 4/13
50% Functions 2/4
42.1% Lines 8/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48117x 127x                 127x                 58x 58x 58x 58x 58x                                                
import { Schema } from 'jtd';
import { isEqual } from 'lodash-es';
import { DateTime } from 'luxon';
import { Tag, TagSort } from './tag';
 
export interface Ext extends Tag {
  type?: 'ext';
  config?: any;
}
 
export const extSchema: Schema = {
  optionalProperties: {
    tag: { type: 'string' },
    name: { type: 'string' },
    config: {},
  }
};
 
export function mapExt(obj: any): Ext {
  obj.type = 'ext';
  obj.origin ||= '';
  obj.modifiedString = obj.modified;
  obj.modified &&= DateTime.fromISO(obj.modified);
  return obj;
}
 
export function writeExt(ext: Ext): Ext {
  const result = { ...ext };
  result.modified = result.modifiedString as any;
  delete result.type;
  delete result.upload;
  delete result.exists;
  delete result.outdated;
  delete result.modifiedString;
  if (result.config) delete result.config._cache;
  return result;
}
 
export function equalsExt(a?: Ext, b?: Ext) {
  if (!a || !b) return false;
  return a.tag === b.tag &&
    a.name === b.name &&
    isEqual(a.config, b.config);
}
 
export type ExtSort = TagSort |
  `config->${string}` | `config->${string},ASC` | `config->${string},DESC`;