Skip to content

Commit

Permalink
feat(docmaps-sdk): remove prefix strings from type names (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
ships authored May 18, 2023
1 parent 29ca9b5 commit 9fa69ad
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 92 deletions.
6 changes: 3 additions & 3 deletions packages/ts-etl/src/command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CrossrefClient } from 'crossref-openapi-client-ts'
import { Command, Option } from '@commander-js/extra-typings'
import { DocmapPublisher, DocmapPublisherT } from 'docmaps-sdk'
import { Publisher, PublisherT } from 'docmaps-sdk'
import { isLeft, right } from 'fp-ts/lib/Either'

import * as crossref from './plugins/crossref'
Expand Down Expand Up @@ -52,7 +52,7 @@ export function MakeCli() {
.option('--publisher.homepage <homepage>', 'homepage of publisher of docmaps to generate (you)')
.option('--publisher.logo <logo>', 'logo of publisher of docmaps to generate (you)')
.action(async (doi, options) => {
const pub = DocmapPublisher.decode({
const pub = Publisher.decode({
id: options['publisher.id'],
name: options['publisher.name'],
homepage: options['publisher.homepage'],
Expand Down Expand Up @@ -124,7 +124,7 @@ export interface CrossrefConfiguration {
*/
export interface ItemOpts {
source: CrossrefConfiguration
publisher: DocmapPublisherT
publisher: PublisherT
}

/**
Expand Down
20 changes: 9 additions & 11 deletions packages/ts-etl/src/plugins/crossref/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const Client = CreateCrossrefClient({})
// for now without going all the way to a graphy representation
// in this procedure.
type RecursiveStepDataChain = {
head: D.DocmapStepT
all: D.DocmapStepT[]
head: D.StepT
all: D.StepT[]
}

function stepsForDoiRecursive(
Expand Down Expand Up @@ -56,7 +56,7 @@ function stepsForDoiRecursive(
},
],
})),
E.chain((action) => pipe(D.DocmapStep.decode(action), mapLeftToUnknownError)),
E.chain((action) => pipe(D.Step.decode(action), mapLeftToUnknownError)),
E.map((s) => ({
all: [s],
head: s,
Expand Down Expand Up @@ -89,18 +89,16 @@ function stepsForDoiRecursive(

const newStep = {
...initialChain.head,
inputs: meta.reduce<D.DocmapThingT[]>(
inputs: meta.reduce<D.ThingT[]>(
(memo, c) =>
memo.concat(
c.head.actions.reduce<D.DocmapThingT[]>((m, a) => m.concat(a.outputs), []),
),
memo.concat(c.head.actions.reduce<D.ThingT[]>((m, a) => m.concat(a.outputs), [])),
[],
),
}

return {
head: newStep,
all: meta.reduce<D.DocmapStepT[]>((m, c) => m.concat(c.all), []).concat([newStep]),
all: meta.reduce<D.StepT[]>((m, c) => m.concat(c.all), []).concat([newStep]),
}
}),
)
Expand Down Expand Up @@ -133,7 +131,7 @@ function stepsForDoiRecursive(
},
],
})),
TE.chainEitherK((rs) => mapLeftToUnknownError(D.DocmapStep.decode(rs))),
TE.chainEitherK((rs) => mapLeftToUnknownError(D.Step.decode(rs))),
TE.map((reviewStep) => ({
head: prefixChain.head,
all: prefixChain.all.concat([reviewStep]),
Expand All @@ -148,7 +146,7 @@ function stepsForDoiRecursive(

export async function fetchPublicationByDoi(
client: CrossrefClient,
publisher: D.DocmapPublisherT,
publisher: D.PublisherT,
inputDoi: string,
): Promise<ErrorOrDocmap> {
const resultTask = pipe(
Expand All @@ -172,7 +170,7 @@ export async function fetchPublicationByDoi(
export function actionForReviewDOI(
client: CrossrefClient,
doi: string,
): TE.TaskEither<Error, D.DocmapActionT> {
): TE.TaskEither<Error, D.ActionT> {
const service = client.works
return pipe(
TE.tryCatch(
Expand Down
12 changes: 6 additions & 6 deletions packages/ts-etl/src/plugins/crossref/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function nameForAuthor(a: { family: string; name?: string; given?: string }): st
return a.name || (a.given ? `${a.family}, ${a.given}` : a.family)
}

export function decodeActionForWork(work: Work): E.Either<Error, D.DocmapActionT> {
export function decodeActionForWork(work: Work): E.Either<Error, D.ActionT> {
return pipe(
E.Do,
// prepare the Thing which will be output
Expand All @@ -35,7 +35,7 @@ export function decodeActionForWork(work: Work): E.Either<Error, D.DocmapActionT
type: 'person',
name: nameForAuthor(a),
})),
E.traverseArray((a) => mapLeftToUnknownError(D.DocmapActor.decode(a))),
E.traverseArray((a) => mapLeftToUnknownError(D.Actor.decode(a))),
E.map((auths) =>
auths.map((a) => ({
actor: a,
Expand All @@ -51,7 +51,7 @@ export function decodeActionForWork(work: Work): E.Either<Error, D.DocmapActionT
participants: wa,
outputs: [wo],
},
D.DocmapAction.decode,
D.Action.decode,
mapLeftToUnknownError,
),
),
Expand All @@ -71,9 +71,9 @@ export function decodeActionForWork(work: Work): E.Either<Error, D.DocmapActionT
* This is an awkward moment that breaks some of the functional abstraction (see comments).
*/
export function stepArrayToDocmap(
publisher: D.DocmapPublisherT,
publisher: D.PublisherT,
inputDoi: string,
[firstStep, ...steps]: D.DocmapStepT[],
[firstStep, ...steps]: D.StepT[],
): ErrorOrDocmap {
// TODO: extract this logic
const dm_id = `https://docmaps-project.github.io/ex/docmap_for/${inputDoi}`
Expand Down Expand Up @@ -103,7 +103,7 @@ export function stepArrayToDocmap(
// this reduction takes advantage of the fact that we have separated the firstStep
// from the ...steps argument, because the first & last step is only singly linked
// (see the last argument to #reduce).
const reduction = steps.reduce<E.Either<Error, Record<string, D.DocmapStepT>>>(
const reduction = steps.reduce<E.Either<Error, Record<string, D.StepT>>>(
(memo, next) => {
if (E.isLeft(memo)) {
return memo //cascade all errors
Expand Down
6 changes: 3 additions & 3 deletions packages/ts-etl/test/unit/crossref/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as cm from '../__fixtures__/crossref'
import * as E from 'fp-ts/lib/Either'
import { inspect } from 'util'
import * as F from '../../../src/plugins/crossref/functions'
import type { DocmapActionT } from 'docmaps-sdk'
import type { ActionT } from 'docmaps-sdk'

function rightOrInspectError<T>(
t: ExecutionContext,
Expand Down Expand Up @@ -31,7 +31,7 @@ test('decodeActionForWork: no authors', async (t) => {
t.true(
rightOrInspectError(
t,
(action: DocmapActionT) => {
(action: ActionT) => {
t.is(action.outputs[0]?.doi, 'mock.decodeAction')
t.deepEqual(action.participants, [])
},
Expand All @@ -55,7 +55,7 @@ test('decodeActionForWork: with authors', async (t) => {
t.true(
rightOrInspectError(
t,
(action: DocmapActionT) => {
(action: ActionT) => {
t.is(action.outputs[0]?.doi, 'mock.decodeAction')
t.is(action.participants[0]?.role, 'author')
t.is(action.participants[1]?.role, 'author')
Expand Down
18 changes: 9 additions & 9 deletions packages/ts-sdk/src/test/__fixtures__/from_root_examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ const el_dm_actor = el_dm_role.map((r) => r['actor'] || [])
export const PartialExamples = {
elife: {
Docmap: el_dm,
DocmapPublisher: el_dm_publisher,
DocmapOnlineAccount: el_dm_acc,
DocmapStep: el_dm_step,
DocmapAction: el_dm_action,
DocmapAssertion: el_dm_assertion,
DocmapThing: el_dm_thing,
DocmapActor: el_dm_actor,
DocmapRoleInTime: el_dm_role,
DocmapManifestation: el_dm_mani,
Publisher: el_dm_publisher,
OnlineAccount: el_dm_acc,
Step: el_dm_step,
Action: el_dm_action,
Assertion: el_dm_assertion,
Thing: el_dm_thing,
Actor: el_dm_actor,
RoleInTime: el_dm_role,
Manifestation: el_dm_mani,
},
}
4 changes: 2 additions & 2 deletions packages/ts-sdk/src/test/typed_graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const g = new TypedGraph(factory)
test('Graph Extraction of a Manifestation', async (t) => {
const mf = (await g.pickStream(OneManifestationQuadstore(), {
type: 'web-page', // selects the Publisher
})) as DocmapsTypes.DocmapManifestationT
})) as DocmapsTypes.ManifestationT

t.is(mf.id, 'https://w3id.org/docmaps/examples/manifestation')
t.is(mf.service?.hostname, 'w3id.org')
Expand Down Expand Up @@ -63,7 +63,7 @@ test('Parsing JSONLD from concrete embo examples', async (t) => {
// test('Graph Extraction of a publisher', async (t) => {
// const pub = await g.pickStream(OnePublisherQuadstore(), {
// 'type': "foaf:organization", // selects the Publisher
// }) as DocmapsTypes.DocmapPublisherT;
// }) as DocmapsTypes.PublisherT;
//
// t.is(pub.id, 'https://w3id.org/docmaps/examples/publisher');
// t.is(pub.name, 'Example Publisher');
Expand Down
54 changes: 27 additions & 27 deletions packages/ts-sdk/src/test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,65 @@ function isRightArray<T>(
)
}

test('Codec parsing DocmapOnlineAccount', (t) => {
const v = ex.elife.DocmapOnlineAccount.flatMap((x) => {
return dm.DocmapOnlineAccount.decode(x)
test('Codec parsing OnlineAccount', (t) => {
const v = ex.elife.OnlineAccount.flatMap((x) => {
return dm.OnlineAccount.decode(x)
})
isRightArray(t, v, 1)
})

test('Codec parsing DocmapPublisher', (t) => {
const v = ex.elife.DocmapPublisher.flatMap((x) => {
return dm.DocmapPublisher.decode(x)
test('Codec parsing Publisher', (t) => {
const v = ex.elife.Publisher.flatMap((x) => {
return dm.Publisher.decode(x)
})
isRightArray(t, v, 2)
})

test('Codec parsing DocmapManifestation', (t) => {
const v = ex.elife.DocmapManifestation.flatMap((x) => {
return dm.DocmapManifestation.decode(x)
test('Codec parsing Manifestation', (t) => {
const v = ex.elife.Manifestation.flatMap((x) => {
return dm.Manifestation.decode(x)
})
isRightArray(t, v, 21)
})

test('Codec parsing DocmapThing', (t) => {
const v = ex.elife.DocmapThing.flatMap((x) => {
return dm.DocmapThing.decode(x)
test('Codec parsing Thing', (t) => {
const v = ex.elife.Thing.flatMap((x) => {
return dm.Thing.decode(x)
})
isRightArray(t, v, 9)
})

test('Codec parsing DocmapRoleInTime', (t) => {
const v = ex.elife.DocmapRoleInTime.flatMap((x) => {
return dm.DocmapRoleInTime.decode(x)
test('Codec parsing RoleInTime', (t) => {
const v = ex.elife.RoleInTime.flatMap((x) => {
return dm.RoleInTime.decode(x)
})
isRightArray(t, v, 9)
})

test('Codec parsing DocmapActor', (t) => {
const v = ex.elife.DocmapActor.flatMap((x) => {
return dm.DocmapActor.decode(x)
test('Codec parsing Actor', (t) => {
const v = ex.elife.Actor.flatMap((x) => {
return dm.Actor.decode(x)
})
isRightArray(t, v, 9)
})

test('Codec parsing DocmapAction', (t) => {
const v = ex.elife.DocmapAction.flatMap((x) => {
return dm.DocmapAction.decode(x)
test('Codec parsing Action', (t) => {
const v = ex.elife.Action.flatMap((x) => {
return dm.Action.decode(x)
})
isRightArray(t, v, 9)
})

test('Codec parsing DocmapAssertion', (t) => {
const v = ex.elife.DocmapAssertion.flatMap((x) => {
return dm.DocmapAssertion.decode(x)
test('Codec parsing Assertion', (t) => {
const v = ex.elife.Assertion.flatMap((x) => {
return dm.Assertion.decode(x)
})
isRightArray(t, v, 6)
})

test('Codec parsing DocmapStep', (t) => {
const v = ex.elife.DocmapStep.flatMap((x) => {
return dm.DocmapStep.decode(x)
test('Codec parsing Step', (t) => {
const v = ex.elife.Step.flatMap((x) => {
return dm.Step.decode(x)
})
isRightArray(t, v, 5)
})
Expand Down
Loading

0 comments on commit 9fa69ad

Please sign in to comment.