From 1cdfbaa59f7e7a6bb5300d7224182dac8dde8111 Mon Sep 17 00:00:00 2001 From: Jonathan Rayback Date: Wed, 5 Jun 2024 20:12:52 -0600 Subject: [PATCH] made small improvements on latest release --- README.md | 6 ++++++ package.json | 2 +- src/api/transform/steps/readCodeFromText.ts | 10 +++++----- src/lib/util/exhaustive.ts | 8 +++++++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5ec17d8..0a1af45 100644 --- a/README.md +++ b/README.md @@ -114,3 +114,9 @@ Run all tests, format the code, transpile for ECMAScript and CommonJS, and write ```bash npm run full-build ``` + +Three files that serve as a good starting point for developers becoming familiar with the project. + +`src/api/encode/text.ts` +`src/api/transform/transformers/transformTextToRaw.ts` +`src/implementation/make.ts` diff --git a/package.json b/package.json index 4b762c1..402aa1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@simple-ssi/simple-cesr", - "version": "0.2.2", + "version": "0.2.3", "description": "A simple, limited, true-to-spec implementation of the CESR protocol.", "type": "module", "access": "public", diff --git a/src/api/transform/steps/readCodeFromText.ts b/src/api/transform/steps/readCodeFromText.ts index aa2c228..1096d8d 100644 --- a/src/api/transform/steps/readCodeFromText.ts +++ b/src/api/transform/steps/readCodeFromText.ts @@ -9,13 +9,13 @@ const readTwoCharCode = (text: Text): Code => text.substring(0, 2) as Code const readFourCharCode = (text: Text): Code => text.substring(0, 4) as Code // reads the code characters from the Text -export const readCodeFromText = (textDomain: Text): Code => { - const selector = textDomain[0] as Selector +export const readCodeFromText = (text: Text): Code => { + const selector = text[0] as Selector return selector !== '0' && selector !== '1' - ? readOneCharCode(textDomain) + ? readOneCharCode(text) : selector === '0' - ? readTwoCharCode(textDomain) + ? readTwoCharCode(text) : selector === '1' - ? readFourCharCode(textDomain) + ? readFourCharCode(text) : exhaustive(selector) } diff --git a/src/lib/util/exhaustive.ts b/src/lib/util/exhaustive.ts index d0bdda1..c198e1d 100644 --- a/src/lib/util/exhaustive.ts +++ b/src/lib/util/exhaustive.ts @@ -1,5 +1,11 @@ // TypeScript exhaustiveness check // see https://www.typescriptlang.org/docs/handbook/2/narrowing.html#exhaustiveness-checking export const exhaustive = (x: never): never => { - throw new Error("Didn't expect to get here") + throw new ExhuastivenessCheckFailure() +} +export class ExhuastivenessCheckFailure extends Error { + constructor () { + super('Exhaustiveness check failed. Should not have been able to get here.') + this.name = 'EXHAUSTIVENESS_CHECK_FAILURE' + } }