From d9f5014cd04efd695b7b00ec15a9a1521b35e7b1 Mon Sep 17 00:00:00 2001 From: tomasciccola <117094913+tomasciccola@users.noreply.github.com> Date: Wed, 31 Jul 2024 15:58:39 -0300 Subject: [PATCH] feat!: add `configMetadata` to `projectSettings` (#197) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add `configMetadata`: with: `name`, `fileVersion` and `buildDate` * add `importDate`, fix tests * make every field of `configMetadata` required * `configMetadata.fileVersion` as COMVER string * remove 'pattern' for `fileVersion`, fix tests, change on `convertConfigMetadata` * typo --------- Co-authored-by: Tomás Ciccola --- proto/projectSettings/v1.proto | 11 +++++++++-- schema/projectSettings/v1.json | 25 +++++++++++++++++++++++++ src/lib/decode-conversions.ts | 19 +++++++++++++++++++ test/fixtures/cached.js | 4 ++++ test/fixtures/good-docs-completed.js | 6 ++++++ test/fixtures/good-docs-minimal.js | 6 ++++++ 6 files changed, 69 insertions(+), 2 deletions(-) diff --git a/proto/projectSettings/v1.proto b/proto/projectSettings/v1.proto index 622619c..324eace 100644 --- a/proto/projectSettings/v1.proto +++ b/proto/projectSettings/v1.proto @@ -20,7 +20,14 @@ message ProjectSettings_1 { repeated bytes relation = 5; }; - optional DefaultPresets defaultPresets = 2; + message ConfigMetadata { + string name = 1; + google.protobuf.Timestamp buildDate = 2; + google.protobuf.Timestamp importDate = 3; + string fileVersion = 4; + } - optional string name = 5; + optional DefaultPresets defaultPresets = 2; + optional ConfigMetadata configMetadata = 3; + optional string name = 4; } diff --git a/schema/projectSettings/v1.json b/schema/projectSettings/v1.json index c3e5faa..9e715f1 100644 --- a/schema/projectSettings/v1.json +++ b/schema/projectSettings/v1.json @@ -24,6 +24,31 @@ }, "required": ["point", "area", "vertex", "line", "relation"], "additionalProperties": false + }, + "configMetadata": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Name of the configuration" + }, + "buildDate": { + "type": "string", + "format": "date-time", + "description": "RFC3339-formatted datetime of when the configuration was built" + }, + "importDate": { + "type": "string", + "format": "date-time", + "description": "RFC3339-formatted datetime of when the configuration was imported to the project" + }, + "fileVersion": { + "type": "string", + "description": "version of the configuration file format as comver (MAJOR.MINOR)" + } + }, + "additionalProperties": false, + "required": ["name", "buildDate", "importDate", "fileVersion"] } }, "required": ["schemaName"], diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index afedc9c..ad5296b 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -24,6 +24,8 @@ import { ExhaustivenessError, VersionIdObject, getVersionId } from './utils.js' import type { Observation, Track } from '../index.js' import type { Observation_1_Attachment } from '../proto/observation/v1.js' import type { Track_1_Position } from '../proto/track/v1.js' +import { ProjectSettings_1_ConfigMetadata } from '../proto/projectSettings/v1.js' +import { ProjectSettings } from '../schema/projectSettings.js' /** Function type for converting a protobuf type of any version for a particular * schema name, and returning the most recent JSONSchema type */ @@ -38,6 +40,10 @@ export const convertProjectSettings: ConvertFunction<'projectSettings'> = ( ) => { const { common, schemaVersion, defaultPresets, ...rest } = message const jsonSchemaCommon = convertCommon(common, versionObj) + let configMetadata + if (rest.configMetadata) { + configMetadata = convertConfigMetadata(rest.configMetadata) + } return { ...jsonSchemaCommon, ...rest, @@ -50,7 +56,20 @@ export const convertProjectSettings: ConvertFunction<'projectSettings'> = ( relation: defaultPresets.relation.map((r) => r.toString('hex')), } : undefined, + configMetadata, + } +} + +function convertConfigMetadata( + configMetadata: ProjectSettings_1_ConfigMetadata +): ProjectSettings['configMetadata'] { + if (!configMetadata?.importDate) { + throw new Error('Missing required property configMetadata.importDate') + } + if (!configMetadata?.buildDate) { + throw new Error('Missing required property configMetadata.buildDate') } + return configMetadata as ProjectSettings['configMetadata'] } export const convertObservation: ConvertFunction<'observation'> = ( diff --git a/test/fixtures/cached.js b/test/fixtures/cached.js index d42f6d3..b0897da 100644 --- a/test/fixtures/cached.js +++ b/test/fixtures/cached.js @@ -33,4 +33,8 @@ export const cachedValues = { }, iconId: randomBytes(32).toString('hex'), docIdRef: randomBytes(32).toString('hex'), + configMetadata: { + buildDate: date, + importDate: date, + }, } diff --git a/test/fixtures/good-docs-completed.js b/test/fixtures/good-docs-completed.js index dec1804..73324eb 100644 --- a/test/fixtures/good-docs-completed.js +++ b/test/fixtures/good-docs-completed.js @@ -87,6 +87,12 @@ export const goodDocsCompleted = [ relation: cachedValues.defaultPresets.point, }, name: 'myProject', + configMetadata: { + name: 'mapeo-config-1', + fileVersion: '1.0', + buildDate: cachedValues.configMetadata.buildDate, + importDate: cachedValues.configMetadata.importDate, + }, deleted: false, }, expected: {}, diff --git a/test/fixtures/good-docs-minimal.js b/test/fixtures/good-docs-minimal.js index 8346d2b..c5708bf 100644 --- a/test/fixtures/good-docs-minimal.js +++ b/test/fixtures/good-docs-minimal.js @@ -36,6 +36,12 @@ export const goodDocsMinimal = [ createdAt: cachedValues.createdAt, updatedAt: cachedValues.updatedAt, createdBy: cachedValues.createdBy, + configMetadata: { + name: 'mapeo-config', + fileVersion: '1.0', + buildDate: cachedValues.configMetadata.buildDate, + importDate: cachedValues.configMetadata.importDate, + }, links: [], deleted: false, },