11import { parseArgs } from 'util'
22import { either , type Either } from '../../adts.js'
3- import { type JSONValueForbiddingSymbolicKeys } from '../parsing.js'
3+ import { type JsonValueForbiddingSymbolicKeys } from '../parsing.js'
44
55export type InvalidJsonError = {
6- readonly kind : 'invalidJSON '
6+ readonly kind : 'invalidJson '
77 readonly message : string
88}
99
1010export const handleInput = async < Result > (
1111 process : NodeJS . Process ,
12- command : ( input : JSONValueForbiddingSymbolicKeys ) => Result ,
12+ command : ( input : JsonValueForbiddingSymbolicKeys ) => Result ,
1313) : Promise < Result > => {
1414 const args = parseArgs ( {
1515 args : process . argv . slice ( 2 ) , // remove `execPath` and `filename`
@@ -25,7 +25,7 @@ export const handleInput = async <Result>(
2525 `Unsupported input format: "${ args . values [ 'input-format' ] } "` ,
2626 )
2727 } else {
28- const input = await readJSON ( process . stdin )
28+ const input = await readJson ( process . stdin )
2929 return either . match ( input , {
3030 left : error => {
3131 throw new Error ( error . message ) // TODO: Improve error reporting.
@@ -35,10 +35,10 @@ export const handleInput = async <Result>(
3535 }
3636}
3737
38- export const readJSON = async (
38+ export const readJson = async (
3939 stream : AsyncIterable < string > ,
40- ) : Promise < Either < InvalidJsonError , JSONValueForbiddingSymbolicKeys > > =>
41- parseJSON ( await readString ( stream ) )
40+ ) : Promise < Either < InvalidJsonError , JsonValueForbiddingSymbolicKeys > > =>
41+ parseJson ( await readString ( stream ) )
4242
4343export const readString = async (
4444 stream : AsyncIterable < string > ,
@@ -50,13 +50,13 @@ export const readString = async (
5050 return input
5151}
5252
53- const parseJSON = (
53+ const parseJson = (
5454 source : string ,
55- ) : Either < InvalidJsonError , JSONValueForbiddingSymbolicKeys > =>
55+ ) : Either < InvalidJsonError , JsonValueForbiddingSymbolicKeys > =>
5656 either . mapLeft (
57- either . tryCatch ( ( ) : JSONValueForbiddingSymbolicKeys => JSON . parse ( source ) ) ,
57+ either . tryCatch ( ( ) : JsonValueForbiddingSymbolicKeys => JSON . parse ( source ) ) ,
5858 jsonParseError => ( {
59- kind : 'invalidJSON ' ,
59+ kind : 'invalidJson ' ,
6060 message :
6161 jsonParseError instanceof Error
6262 ? jsonParseError . message
0 commit comments