From 9d776a7b0c47e2ba300054b1c9e9f6cd3d0c676b Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Wed, 4 Oct 2023 14:34:12 -0400 Subject: [PATCH] fix: fix DataType.getByDocId implementation to match type definition --- src/datatype/index.js | 3 ++- test-types/data-types.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/datatype/index.js b/src/datatype/index.js index 81c7b9f1e..698c9f58b 100644 --- a/src/datatype/index.js +++ b/src/datatype/index.js @@ -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 */ diff --git a/test-types/data-types.ts b/test-types/data-types.ts index 0362fdeb3..f93833ad4 100644 --- a/test-types/data-types.ts +++ b/test-types/data-types.ts @@ -55,6 +55,9 @@ Expect> const manyObservations = await mapeoProject.observation.getMany() Expect> +const observationByDocId = await mapeoProject.observation.getByDocId('abc') +Expect> + const observationByVersionId = await mapeoProject.observation.getByVersionId( 'abc' ) @@ -71,6 +74,9 @@ Expect> const manyPresets = await mapeoProject.preset.getMany() Expect> +const presetByDocId = await mapeoProject.preset.getByDocId('abc') +Expect> + const presetByVersionId = await mapeoProject.preset.getByVersionId('abc') Expect> @@ -85,5 +91,8 @@ Expect> const manyFields = await mapeoProject.field.getMany() Expect> +const fieldByDocId = await mapeoProject.field.getByDocId('abc') +Expect> + const fieldByVersionId = await mapeoProject.field.getByVersionId('abc') Expect>