Skip to content

Commit

Permalink
feat!: add configMetadata to projectSettings (#197)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
tomasciccola and Tomás Ciccola authored Jul 31, 2024
1 parent d4e000f commit d9f5014
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
11 changes: 9 additions & 2 deletions proto/projectSettings/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
25 changes: 25 additions & 0 deletions schema/projectSettings/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
19 changes: 19 additions & 0 deletions src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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,
Expand All @@ -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'> = (
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/cached.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ export const cachedValues = {
},
iconId: randomBytes(32).toString('hex'),
docIdRef: randomBytes(32).toString('hex'),
configMetadata: {
buildDate: date,
importDate: date,
},
}
6 changes: 6 additions & 0 deletions test/fixtures/good-docs-completed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/good-docs-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit d9f5014

Please sign in to comment.