Skip to content

Commit

Permalink
Handle indeterminate ID types correctly
Browse files Browse the repository at this point in the history
Refs #1834, #2209
  • Loading branch information
thewilkybarkid committed Jan 28, 2025
1 parent 41f822a commit 6d3f912
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 47 deletions.
40 changes: 13 additions & 27 deletions src/crossref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as E from 'fp-ts/lib/Either.js'
import * as O from 'fp-ts/lib/Option.js'
import * as RTE from 'fp-ts/lib/ReaderTaskEither.js'
import * as RA from 'fp-ts/lib/ReadonlyArray.js'
import type { Refinement } from 'fp-ts/lib/Refinement.js'
import { flow, pipe } from 'fp-ts/lib/function.js'
import { isString } from 'fp-ts/lib/string.js'
import { Status } from 'hyper-ts'
Expand All @@ -27,9 +26,11 @@ import type {
EcoevorxivPreprintId,
EdarxivPreprintId,
EngrxivPreprintId,
IndeterminatePreprintId,
MedrxivPreprintId,
MetaarxivPreprintId,
OsfPreprintsPreprintId,
PreprintId,
PreprintsorgPreprintId,
PsyarxivPreprintId,
ResearchSquarePreprintId,
Expand All @@ -40,30 +41,7 @@ import type {
VerixivPreprintId,
} from './types/preprint-id.js'

export type CrossrefPreprintId =
| AdvancePreprintId
| AfricarxivOsfPreprintId
| AuthoreaPreprintId
| BiorxivPreprintId
| ChemrxivPreprintId
| CurvenotePreprintId
| EartharxivPreprintId
| EcoevorxivPreprintId
| EdarxivPreprintId
| EngrxivPreprintId
| MedrxivPreprintId
| MetaarxivPreprintId
| OsfPreprintsPreprintId
| PreprintsorgPreprintId
| PsyarxivPreprintId
| ResearchSquarePreprintId
| ScieloPreprintId
| ScienceOpenPreprintId
| SocarxivPreprintId
| TechrxivPreprintId
| VerixivPreprintId

export const isCrossrefPreprintDoi: Refinement<Doi, CrossrefPreprintId['value']> = hasRegistrant(
const crossrefDoiPrefixes = [
'1101',
'1590',
'12688',
Expand All @@ -84,10 +62,18 @@ export const isCrossrefPreprintDoi: Refinement<Doi, CrossrefPreprintId['value']>
'35542',
'36227',
'62329',
)
] as const

type CrossrefDoiPrefix = (typeof crossrefDoiPrefixes)[number]

export type CrossrefPreprintId = Extract<PreprintId, { value: Doi<CrossrefDoiPrefix> }>

export type IndeterminateCrossrefPreprintId = Extract<IndeterminatePreprintId, { value: Doi<CrossrefDoiPrefix> }>

export const isCrossrefPreprintDoi = hasRegistrant(...crossrefDoiPrefixes)

export const getPreprintFromCrossref = flow(
(id: CrossrefPreprintId) => getWork(id.value),
(id: IndeterminateCrossrefPreprintId) => getWork(id.value),
RTE.local(revalidateIfStale()),
RTE.local(useStaleCache()),
RTE.local(timeoutRequest(2000)),
Expand Down
31 changes: 11 additions & 20 deletions src/datacite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as E from 'fp-ts/lib/Either.js'
import * as O from 'fp-ts/lib/Option.js'
import * as RTE from 'fp-ts/lib/ReaderTaskEither.js'
import * as RA from 'fp-ts/lib/ReadonlyArray.js'
import type { Refinement } from 'fp-ts/lib/Refinement.js'
import { flow, identity, pipe } from 'fp-ts/lib/function.js'
import { Status } from 'hyper-ts'
import * as D from 'io-ts/lib/Decoder.js'
Expand All @@ -22,33 +21,25 @@ import type {
AfricarxivZenodoPreprintId,
ArcadiaSciencePreprintId,
ArxivPreprintId,
IndeterminatePreprintId,
OsfPreprintId,
PreprintId,
PsychArchivesPreprintId,
ZenodoPreprintId,
} from './types/preprint-id.js'

export type DatacitePreprintId =
| AfricarxivFigsharePreprintId
| AfricarxivUbuntunetPreprintId
| AfricarxivZenodoPreprintId
| ArcadiaSciencePreprintId
| ArxivPreprintId
| OsfPreprintId
| PsychArchivesPreprintId
| ZenodoPreprintId
const dataciteDoiPrefixes = ['5281', '6084', '17605', '23668', '48550', '57844', '60763'] as const

export const isDatacitePreprintDoi: Refinement<Doi, DatacitePreprintId['value']> = hasRegistrant(
'5281',
'6084',
'17605',
'23668',
'48550',
'57844',
'60763',
)
type DataciteDoiPrefix = (typeof dataciteDoiPrefixes)[number]

export type DatacitePreprintId = Extract<PreprintId, { value: Doi<DataciteDoiPrefix> }>

export type IndeterminateDatacitePreprintId = Extract<IndeterminatePreprintId, { value: Doi<DataciteDoiPrefix> }>

export const isDatacitePreprintDoi = hasRegistrant(...dataciteDoiPrefixes)

export const getPreprintFromDatacite = flow(
(id: DatacitePreprintId) => getWork(id.value),
(id: IndeterminateDatacitePreprintId) => getWork(id.value),
RTE.local(revalidateIfStale()),
RTE.local(useStaleCache()),
RTE.local(timeoutRequest(2000)),
Expand Down

0 comments on commit 6d3f912

Please sign in to comment.