Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: device -> deviceInfo & new schema #128

Merged
merged 5 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions proto/device/v1.proto → proto/deviceInfo/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ import "google/protobuf/timestamp.proto";
import "common/v1.proto";
import "options.proto";

message Device_1 {
message DeviceInfo_1 {
// **DO NOT CHANGE dataTypeId** generated with `openssl rand -hex 6`
option (dataTypeId) = "e96e6c68fcc0";
option (schemaName) = "device";
option (schemaName) = "deviceInfo";

Common_1 common = 1;

string action = 5;
bytes authorId = 6;
bytes projectId = 7;
string signature = 8;
int32 authorIndex = 9;
int32 deviceIndex = 10;
string capabilityType = 11;
string name = 5;
}
35 changes: 0 additions & 35 deletions schema/device/v1.json

This file was deleted.

18 changes: 18 additions & 0 deletions schema/deviceInfo/v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://mapeo.world/schemas/device/v1.json",
"title": "Device Info",
"type": "object",
"properties": {
"schemaName": {
"type": "string",
"const": "deviceInfo"
},
"name": {
"type": "string",
"description": "Name of the device"
}
},
"required": ["schemaName", "name"],
"additionalProperties": false
}
6 changes: 3 additions & 3 deletions src/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
convertObservation,
convertPreset,
convertRole,
convertDevice,
convertDeviceInfo,
convertCoreOwnership,
} from './lib/decode-conversions.js'
// @ts-ignore
Expand Down Expand Up @@ -61,8 +61,8 @@ export function decode(buf: Buffer, versionObj: VersionIdObject): MapeoDoc {
return convertPreset(message, versionObj)
case 'role':
return convertRole(message, versionObj)
case 'device':
return convertDevice(message, versionObj)
case 'deviceInfo':
return convertDeviceInfo(message, versionObj)
case 'coreOwnership':
return convertCoreOwnership(message, versionObj)
default:
Expand Down
6 changes: 3 additions & 3 deletions src/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
convertPreset,
convertProject,
convertRole,
convertDevice,
convertDeviceInfo,
convertCoreOwnership,
} from './lib/encode-converstions.js'

Expand Down Expand Up @@ -54,8 +54,8 @@ export function encode(mapeoDoc: OmitUnion<MapeoDoc, 'versionId'>): Buffer {
protobuf = Encode[mapeoDoc.schemaName](message).finish()
break
}
case 'device': {
const message = convertDevice(mapeoDoc)
case 'deviceInfo': {
const message = convertDeviceInfo(mapeoDoc)
protobuf = Encode[mapeoDoc.schemaName](message).finish()
break
}
Expand Down
4 changes: 1 addition & 3 deletions src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const convertRole: ConvertFunction<'role'> = (message, versionObj) => {
}
}

export const convertDevice: ConvertFunction<'device'> = (
export const convertDeviceInfo: ConvertFunction<'deviceInfo'> = (
message,
versionObj
) => {
Expand All @@ -144,8 +144,6 @@ export const convertDevice: ConvertFunction<'device'> = (
return {
...jsonSchemaCommon,
...rest,
authorId: message.authorId.toString('hex'),
projectId: message.projectId.toString('hex'),
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/lib/encode-converstions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,10 @@ export const convertRole: ConvertFunction<'role'> = (mapeoDoc) => {
}
}

export const convertDevice: ConvertFunction<'device'> = (mapeoDoc) => {
export const convertDeviceInfo: ConvertFunction<'deviceInfo'> = (mapeoDoc) => {
return {
common: convertCommon(mapeoDoc),
...mapeoDoc,
authorId: Buffer.from(mapeoDoc.authorId, 'hex'),
projectId: Buffer.from(mapeoDoc.projectId, 'hex'),
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import {
import { dataTypeIds } from './config.js'

/** Temporary: once we have completed this module everything should be supported */
type SupportedSchemaNames = 'project' | 'observation' | 'field' | 'preset' | 'role' | 'device' | 'coreOwnership'
type SupportedSchemaNames =
| 'project'
| 'observation'
| 'field'
| 'preset'
| 'role'
| 'deviceInfo'
| 'coreOwnership'

export type SchemaName = Extract<keyof typeof dataTypeIds, SupportedSchemaNames>
export type SchemaNameAll = keyof typeof dataTypeIds
Expand Down
10 changes: 2 additions & 8 deletions test/fixtures/good-docs-completed.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,11 @@ export const goodDocsCompleted = [
doc: {
docId: cachedValues.docId,
versionId: cachedValues.versionId,
schemaName: 'device',
schemaName: 'deviceInfo',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
links: [],
action: 'ban',
authorId: cachedValues.authorId,
projectId: cachedValues.projectId,
signature: 'mySignature',
authorIndex: 1,
deviceIndex: 10,
capabilityType: 'someCapability',
name: 'my device name',
},
expected: {},
},
Expand Down
10 changes: 2 additions & 8 deletions test/fixtures/good-docs-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,11 @@ export const goodDocsMinimal = [
doc: {
docId: cachedValues.docId,
versionId: cachedValues.versionId,
schemaName: 'device',
schemaName: 'deviceInfo',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
links: [],
action: 'ban',
authorId: cachedValues.authorId,
projectId: cachedValues.projectId,
signature: 'mySignature',
capabilityType: 'someCapability',
authorIndex: 0,
deviceIndex: 0,
name: 'my device name',
},
expected: {},
},
Expand Down
Loading