MCPcopy Create free account
hub / github.com/code-pushup/cli / createTolerantCodec

Function createTolerantCodec

packages/utils/src/lib/wal.ts:67–86  ·  view source on GitHub ↗
(codec: {
  encode: (v: I) => O;
  decode: (d: O) => I;
})

Source from the content-addressed store, hash-verified

65};
66
67export const createTolerantCodec = <I, O = string>(codec: {
68 encode: (v: I) => O;
69 decode: (d: O) => I;
70}): Codec<I | InvalidEntry<O>, O> => {
71 const { encode, decode } = codec;
72
73 return {
74 encode: v =>
75 v && typeof v === 'object' && '__invalid' in v
76 ? (v as InvalidEntry<O>).raw
77 : encode(v as I),
78 decode: d => {
79 try {
80 return decode(d);
81 } catch {
82 return { __invalid: true, raw: d };
83 }
84 },
85 };
86};
87
88export function filterValidRecords<T>(
89 records: (T | InvalidEntry<unknown>)[],

Callers 2

constructorMethod · 0.85
wal.unit.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected