Skip to content

Commit

Permalink
feat(ts-sdk): add typing for assertions (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
ships authored May 3, 2023
1 parent 762eef7 commit 5e427e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/ts-sdk/src/test/__fixtures__/from_root_examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const el_dm_publisher = el_dm.flatMap((dm) => dm['publisher'] || [])
const el_dm_acc = el_dm_publisher.flatMap((p) => p['account'] || [])
const el_dm_step: any[] = el_dm.flatMap((dm) => Object.values(dm['steps']) || [])
const el_dm_action = el_dm_step.flatMap((s) => s['actions'] || [])
const el_dm_assertion = el_dm_step.flatMap((s) => s['assertions'] || [])
const el_dm_thing = el_dm_action.flatMap((a) => a['outputs'] || [])
const el_dm_mani = el_dm_thing.flatMap((t) => t['content'] || [])
const el_dm_role = el_dm_action.flatMap((a) => a['participants'] || [])
Expand All @@ -55,6 +56,7 @@ export const PartialExamples = {
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,
Expand Down
7 changes: 7 additions & 0 deletions packages/ts-sdk/src/test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ test('Codec parsing DocmapAction', (t) => {
isRightArray(t, v, 9)
})

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

test('Codec parsing DocmapStep', (t) => {
const v = ex.elife.DocmapStep.flatMap((x) => {
return dm.DocmapStep.decode(x)
Expand Down
15 changes: 14 additions & 1 deletion packages/ts-sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,25 @@ export const DocmapAction = t.intersection([
}),
])

const DocmapStatus = t.string

export const DocmapAssertion = t.intersection([
t.type({
item: t.unknown,
status: DocmapStatus,
}),
t.partial({
happened: DateFromUnknown,
}),
])

export const DocmapStep = t.intersection([
t.type({
actions: t.array(DocmapAction),
inputs: t.array(DocmapThing),

// TODO: make this smarter
assertions: t.array(t.unknown),
assertions: t.array(DocmapAssertion),
}),
t.partial({
id: t.string,
Expand Down Expand Up @@ -155,6 +167,7 @@ export type DocmapActionT = t.TypeOf<typeof DocmapAction>
export type DocmapThingT = t.TypeOf<typeof DocmapThing>
export type DocmapRoleInTimeT = t.TypeOf<typeof DocmapRoleInTime>
export type DocmapActorT = t.TypeOf<typeof DocmapActor>
export type DocmapAssertionT = t.TypeOf<typeof DocmapAssertion>

/** DocmapsFactory
*
Expand Down

0 comments on commit 5e427e9

Please sign in to comment.