From 6536b11fca0a247818421d01404cbdf49228d8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Ciccola?= Date: Mon, 19 Aug 2024 13:53:25 -0300 Subject: [PATCH 1/4] start changes on required values --- proto/common/v1.proto | 2 +- proto/field/v1.proto | 8 ++++---- proto/observation/v1.proto | 8 ++++---- proto/preset/v1.proto | 2 +- schema/field/v1.json | 11 ++++++++++- schema/observation/v1.json | 7 ++++--- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/proto/common/v1.proto b/proto/common/v1.proto index 8952417..65701d1 100644 --- a/proto/common/v1.proto +++ b/proto/common/v1.proto @@ -7,7 +7,7 @@ import "versionId/v1.proto"; message Common_1 { // 32-byte random generated number - optional bytes docId = 1 [(required) = true]; + bytes docId = 1 [(required) = true]; repeated VersionId_1 links = 2; google.protobuf.Timestamp createdAt = 3 [(required) = true]; google.protobuf.Timestamp updatedAt = 4 [(required) = true]; diff --git a/proto/field/v1.proto b/proto/field/v1.proto index 56da9b6..ffb7ed3 100644 --- a/proto/field/v1.proto +++ b/proto/field/v1.proto @@ -14,7 +14,7 @@ message Field_1 { Common_1 common = 1; - optional string tagKey = 5 [(required) = true]; + string tagKey = 5 [(required) = true]; enum Type { type_unspecified = 0; text = 1; @@ -23,7 +23,7 @@ message Field_1 { selectMultiple = 4; } Type type = 6 [(required) = true]; - optional string label = 7 [(required) = true]; + string label = 7 [(required) = true]; enum Appearance { appearance_unspecified = 0; multiline = 1; @@ -36,7 +36,7 @@ message Field_1 { TagValue_1.PrimitiveValue value = 2; } repeated Option options = 10; - optional bool universal = 11; + bool universal = 11; optional string placeholder = 12; - optional string helperText = 13; + string helperText = 13; } diff --git a/proto/observation/v1.proto b/proto/observation/v1.proto index f81b0e2..31847c7 100644 --- a/proto/observation/v1.proto +++ b/proto/observation/v1.proto @@ -14,8 +14,8 @@ message Observation_1 { Common_1 common = 1; - optional double lat = 5; - optional double lon = 6; + double lat = 5; + double lon = 6; // ATTACHMENT enum AttachmentType { @@ -37,7 +37,7 @@ message Observation_1 { // METADATA message Metadata { - optional bool manualLocation = 1; + bool manualLocation = 1; message Position { google.protobuf.Timestamp timestamp = 1; @@ -51,7 +51,7 @@ message Observation_1 { double speed = 5; double accuracy = 6; } - optional Coords coords = 3; + Coords coords = 3; } message PositionProvider { diff --git a/proto/preset/v1.proto b/proto/preset/v1.proto index d98931f..b7f238a 100644 --- a/proto/preset/v1.proto +++ b/proto/preset/v1.proto @@ -21,7 +21,7 @@ message Preset_1 { map addTags = 8; map removeTags = 9; repeated FieldRef fieldRefs = 10; - optional IconRef iconRef = 11; + IconRef iconRef = 11; repeated string terms = 12; string color = 13; diff --git a/schema/field/v1.json b/schema/field/v1.json index 3f3af8a..4662d47 100644 --- a/schema/field/v1.json +++ b/schema/field/v1.json @@ -102,6 +102,15 @@ "type": "string" } }, - "required": ["tagKey", "type", "label", "schemaName"], + "required": [ + "tagKey", + "type", + "label", + "schemaName", + "tagKey", + "label", + "universal", + "helperText" + ], "additionalProperties": false } diff --git a/schema/observation/v1.json b/schema/observation/v1.json index d8077f8..37bd655 100644 --- a/schema/observation/v1.json +++ b/schema/observation/v1.json @@ -7,7 +7,7 @@ "position": { "description": "Position details", "type": "object", - "required": ["mocked"], + "required": ["mocked", "coords"], "properties": { "timestamp": { "description": "Timestamp of when the current position was obtained", @@ -179,9 +179,10 @@ } } }, - "additionalProperties": false + "additionalProperties": false, + "required": ["manualLocation"] } }, - "required": ["schemaName", "tags", "attachments", "metadata"], + "required": ["schemaName", "tags", "attachments", "lat", "lon"], "additionalProperties": false } From 4c4511cb4839fb52e9a9b2f65e64649bce30cde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Ciccola?= Date: Mon, 19 Aug 2024 14:15:57 -0300 Subject: [PATCH 2/4] remove duplicate fields on JSONSchema, solve type errors and tests --- schema/field/v1.json | 2 -- schema/preset/v1.json | 3 ++- src/lib/decode-conversions.ts | 5 ++++- src/lib/encode-conversions.ts | 2 +- test/fixtures/good-docs-completed.js | 1 + test/fixtures/good-docs-minimal.js | 10 +++++++++- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/schema/field/v1.json b/schema/field/v1.json index 4662d47..d438d59 100644 --- a/schema/field/v1.json +++ b/schema/field/v1.json @@ -107,8 +107,6 @@ "type", "label", "schemaName", - "tagKey", - "label", "universal", "helperText" ], diff --git a/schema/preset/v1.json b/schema/preset/v1.json index 29c7e06..8bbb5ec 100644 --- a/schema/preset/v1.json +++ b/schema/preset/v1.json @@ -131,7 +131,8 @@ "fieldRefs", "schemaName", "terms", - "color" + "color", + "iconRef" ], "additionalProperties": false } diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index e230223..9cc4910 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -95,7 +95,8 @@ export const convertObservation: ConvertFunction<'observation'> = ( ...rest, attachments: message.attachments.map(convertAttachment), tags: convertTags(message.tags), - metadata: message.metadata || {}, + // @ts-ignore + metadata: message.metadata || { manualLocation: true }, presetRef, } return obs @@ -158,6 +159,8 @@ export const convertPreset: ConvertFunction<'preset'> = ( docId: rest.iconRef.docId.toString('hex'), versionId: getVersionId(rest.iconRef.versionId), } + } else { + throw new Error('missing iconRef for preset') } return { ...jsonSchemaCommon, diff --git a/src/lib/encode-conversions.ts b/src/lib/encode-conversions.ts index 2b36e31..f82e34b 100644 --- a/src/lib/encode-conversions.ts +++ b/src/lib/encode-conversions.ts @@ -102,7 +102,7 @@ export const convertObservation: ConvertFunction<'observation'> = ( mapeoDoc ) => { const attachments = mapeoDoc.attachments.map(convertAttachment) - const metadata: Observation_1_Metadata = mapeoDoc.metadata && { + const metadata: Observation_1_Metadata | undefined = mapeoDoc.metadata && { ...Observation_1_Metadata.fromPartial(mapeoDoc.metadata), } let presetRef diff --git a/test/fixtures/good-docs-completed.js b/test/fixtures/good-docs-completed.js index 074f4d9..5ab113c 100644 --- a/test/fixtures/good-docs-completed.js +++ b/test/fixtures/good-docs-completed.js @@ -122,6 +122,7 @@ export const goodDocsCompleted = [ value: 'somePrimitiveTagValue', }, ], + helperText: '', deleted: false, }, expected: {}, diff --git a/test/fixtures/good-docs-minimal.js b/test/fixtures/good-docs-minimal.js index 24b50f6..671950d 100644 --- a/test/fixtures/good-docs-minimal.js +++ b/test/fixtures/good-docs-minimal.js @@ -21,9 +21,11 @@ export const goodDocsMinimal = [ updatedAt: cachedValues.updatedAt, createdBy: cachedValues.createdBy, links: [], + lat: 24.0424, + lon: 21.0214, attachments: [], tags: {}, - metadata: {}, + metadata: { manualLocation: false }, deleted: false, }, expected: {}, @@ -60,6 +62,8 @@ export const goodDocsMinimal = [ label: 'my label', type: 'text', deleted: false, + universal: false, + helperText: '', }, expected: {}, }, @@ -78,6 +82,10 @@ export const goodDocsMinimal = [ addTags: {}, removeTags: {}, fieldRefs: [], + iconRef: { + docId: cachedValues.refs.docId, + versionId: cachedValues.refs.versionId, + }, terms: [], deleted: false, color: '#ff00ff', From c421d4d1dd20b8423963b5c671ed653b330658d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Ciccola?= Date: Thu, 22 Aug 2024 15:50:58 -0300 Subject: [PATCH 3/4] make coords optional --- proto/observation/v1.proto | 2 +- schema/observation/v1.json | 10 +++++++++- src/lib/decode-conversions.ts | 3 +-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/proto/observation/v1.proto b/proto/observation/v1.proto index 978652c..69445d3 100644 --- a/proto/observation/v1.proto +++ b/proto/observation/v1.proto @@ -52,7 +52,7 @@ message Observation_1 { double speed = 5; double accuracy = 6; } - Coords coords = 3; + optional Coords coords = 3 [(required) = true]; } message PositionProvider { diff --git a/schema/observation/v1.json b/schema/observation/v1.json index cc2d2aa..d7089ce 100644 --- a/schema/observation/v1.json +++ b/schema/observation/v1.json @@ -7,7 +7,7 @@ "position": { "description": "Position details", "type": "object", - "required": ["mocked", "coords"], + "required": ["mocked"], "properties": { "timestamp": { "description": "Timestamp of when the current position was obtained", @@ -22,6 +22,14 @@ "coords": { "description": "Position details, should be self explanatory. Units in meters", "type": "object", + "required": [ + "latitude", + "longitude", + "altitude", + "heading", + "speed", + "accuracy" + ], "properties": { "latitude": { "type": "number" diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index 9cc4910..9d19541 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -95,8 +95,7 @@ export const convertObservation: ConvertFunction<'observation'> = ( ...rest, attachments: message.attachments.map(convertAttachment), tags: convertTags(message.tags), - // @ts-ignore - metadata: message.metadata || { manualLocation: true }, + metadata: message.metadata, presetRef, } return obs From 0f3b0498109e5c690679581c6c9a59815966465f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Ciccola?= Date: Thu, 22 Aug 2024 15:52:03 -0300 Subject: [PATCH 4/4] wrong `[(required) = true]` on optional `Coords` --- proto/observation/v1.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/observation/v1.proto b/proto/observation/v1.proto index 69445d3..74d727e 100644 --- a/proto/observation/v1.proto +++ b/proto/observation/v1.proto @@ -52,7 +52,7 @@ message Observation_1 { double speed = 5; double accuracy = 6; } - optional Coords coords = 3 [(required) = true]; + optional Coords coords = 3; } message PositionProvider {