-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert: remove
getByDocId
optional parameter
This reverts commit 56f7e18 and replaces it with an internal-only function, `getByDocIdIfExists`.
- Loading branch information
Showing
9 changed files
with
169 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NotFoundError } from '../errors.js' | ||
/** @import { DataStore } from '../datastore/index.js' */ | ||
/** @import { MapeoDocMap, MapeoValueMap } from '../types.js' */ | ||
/** @import { DataType, MapeoDocTables } from './index.js' */ | ||
|
||
/** | ||
* @template {MapeoDocTables} TTable | ||
* @template {TTable['_']['name']} TSchemaName | ||
* @template {MapeoDocMap[TSchemaName]} TDoc | ||
* @template {MapeoValueMap[TSchemaName]} TValue | ||
* @param {DataType<DataStore, TTable, TSchemaName, TDoc, TValue>} dataType | ||
* @param {string} docId | ||
* @returns {Promise<null | TDoc & { forks: string[] }>} | ||
*/ | ||
export async function getByDocIdIfExists(dataType, docId) { | ||
try { | ||
return await dataType.getByDocId(docId) | ||
} catch (err) { | ||
if (err instanceof NotFoundError) return null | ||
throw err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { testenv } from './test-helpers.js' | ||
import test, { describe } from 'node:test' | ||
import assert from 'node:assert/strict' | ||
import { getByDocIdIfExists } from '../../src/datatype/get-if-exists.js' | ||
import { valueOf } from '@comapeo/schema' | ||
import { generate } from '@mapeo/mock-data' | ||
|
||
describe('getByDocIdIfExists', () => { | ||
test('resolves with null if no document exists with that ID', async () => { | ||
const { dataType } = await testenv() | ||
assert.equal(await getByDocIdIfExists(dataType, 'foo bar'), null) | ||
}) | ||
|
||
test('resolves with the document if it exists', async () => { | ||
const { dataType } = await testenv() | ||
const fixture = valueOf(generate('observation')[0]) | ||
const observation = await dataType.create(fixture) | ||
assert(await getByDocIdIfExists(dataType, observation.docId)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.