Skip to content

Commit

Permalink
fix: fix encode() parameter type (#97)
Browse files Browse the repository at this point in the history
Had forgotten to update it from version -> versionId
  • Loading branch information
gmaclennan authored Aug 3, 2023
1 parent 2de7197 commit f92b903
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
* Encode a an object validated against a schema as a binary protobuf prefixed
* with the encoded data type ID and schema version, to send to an hypercore.
*/
export function encode(mapeoDoc: OmitUnion<MapeoDoc, 'version'>): Buffer {
export function encode(mapeoDoc: OmitUnion<MapeoDoc, 'versionId'>): Buffer {
const { schemaName } = mapeoDoc
const schemaVersion = currentSchemaVersions[schemaName]
const schemaDef = { schemaName, schemaVersion }
Expand Down
7 changes: 5 additions & 2 deletions src/lib/encode-converstions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { Observation_5_Metadata } from '../proto/observation/v5.js'
/** Function type for converting a protobuf type of any version for a particular
* schema name, and returning the most recent JSONSchema type */
type ConvertFunction<TSchemaName extends SchemaName> = (
mapeoDoc: Extract<OmitUnion<MapeoDoc, 'version'>, { schemaName: TSchemaName }>
mapeoDoc: Extract<
OmitUnion<MapeoDoc, 'versionId'>,
{ schemaName: TSchemaName }
>
) => CurrentProtoTypes[TSchemaName]

export const convertProject: ConvertFunction<'project'> = (mapeoDoc) => {
Expand Down Expand Up @@ -85,7 +88,7 @@ export const convertObservation: ConvertFunction<'observation'> = (
}

function convertCommon(
common: Omit<MapeoCommon, 'version'>
common: Omit<MapeoCommon, 'versionId'>
): ProtoTypesWithSchemaInfo['common'] {
return {
docId: Buffer.from(common.docId, 'hex'),
Expand Down
4 changes: 1 addition & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export type DataTypeId = Values<typeof dataTypeIds>
*/
type PickUnion<T, K extends keyof T> = T extends any ? Pick<T, K> : never
/** Omit over a union, that keeps it as a distributive type */
export type OmitUnion<T, K extends keyof any> = T extends any
? Omit<T, K>
: never
export type OmitUnion<T, K extends keyof T> = T extends any ? Omit<T, K> : never
/** Return a union of object values */
type Values<T> = T[keyof T]

0 comments on commit f92b903

Please sign in to comment.