Skip to content

Commit

Permalink
fix: fix DataType.getByDocId implementation to match type definition (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 authored Oct 4, 2023
1 parent 16c9250 commit 015ee08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/datatype/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ export class DataType {
*/
async getByDocId(docId) {
const result = this.#sql.getByDocId.get({ docId })
return result ? deNullify(result) : result
if (!result) throw new Error('Not found')
return deNullify(result)
}

/** @param {string} versionId */
Expand Down
9 changes: 9 additions & 0 deletions test-types/data-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Expect<Equal<ObservationWithForks, typeof updatedObservation>>
const manyObservations = await mapeoProject.observation.getMany()
Expect<Equal<ObservationWithForks[], typeof manyObservations>>

const observationByDocId = await mapeoProject.observation.getByDocId('abc')
Expect<Equal<Observation & { forks: string[] }, typeof observationByDocId>>

const observationByVersionId = await mapeoProject.observation.getByVersionId(
'abc'
)
Expand All @@ -71,6 +74,9 @@ Expect<Equal<PresetWithForks, typeof updatedPreset>>
const manyPresets = await mapeoProject.preset.getMany()
Expect<Equal<PresetWithForks[], typeof manyPresets>>

const presetByDocId = await mapeoProject.preset.getByDocId('abc')
Expect<Equal<Preset & { forks: string[] }, typeof presetByDocId>>

const presetByVersionId = await mapeoProject.preset.getByVersionId('abc')
Expect<Equal<Preset, typeof presetByVersionId>>

Expand All @@ -85,5 +91,8 @@ Expect<Equal<FieldWithForks, typeof updatedField>>
const manyFields = await mapeoProject.field.getMany()
Expect<Equal<FieldWithForks[], typeof manyFields>>

const fieldByDocId = await mapeoProject.field.getByDocId('abc')
Expect<Equal<Field & { forks: string[] }, typeof fieldByDocId>>

const fieldByVersionId = await mapeoProject.field.getByVersionId('abc')
Expect<Equal<Field, typeof fieldByVersionId>>

0 comments on commit 015ee08

Please sign in to comment.