Adding a new URI for GPX technical data and changing the index of wpt, rte and trk.

This commit is contained in:
Eric van der Vlist 2022-11-15 14:39:52 +01:00
parent 5fdd63103e
commit 947f4dff3a
10 changed files with 79 additions and 94 deletions

View File

@ -39,10 +39,10 @@ Object {
},
},
Object {
"id": "gpx/4320000000000000/2trk/000000",
"key": "gpx/4320000000000000/2trk/000000",
"id": "gpx/4320000000000000/3trk/000000",
"key": "gpx/4320000000000000/3trk/000000",
"value": Object {
"rev": "1-46d2f0dcad2299e6ba2830cb1e10b234",
"rev": "1-4c114f3ae0073151e4082ff1d220c2a4",
},
},
],
@ -89,17 +89,17 @@ Object {
},
Object {
"doc": Object {
"_id": "gpx/4320000000000000/2trk/000000",
"_rev": "1-46d2f0dcad2299e6ba2830cb1e10b234",
"_id": "gpx/4320000000000000/3trk/000000",
"_rev": "1-4c114f3ae0073151e4082ff1d220c2a4",
"doc": Object {
"number": 0,
},
"type": "trk",
},
"id": "gpx/4320000000000000/2trk/000000",
"key": "gpx/4320000000000000/2trk/000000",
"id": "gpx/4320000000000000/3trk/000000",
"key": "gpx/4320000000000000/3trk/000000",
"value": Object {
"rev": "1-46d2f0dcad2299e6ba2830cb1e10b234",
"rev": "1-4c114f3ae0073151e4082ff1d220c2a4",
},
},
],
@ -122,17 +122,17 @@ Object {
},
},
Object {
"id": "gpx/4320000000000000/2trk/000000",
"key": "gpx/4320000000000000/2trk/000000",
"id": "gpx/4320000000000000/3trk/000000",
"key": "gpx/4320000000000000/3trk/000000",
"value": Object {
"rev": "1-46d2f0dcad2299e6ba2830cb1e10b234",
"rev": "1-4c114f3ae0073151e4082ff1d220c2a4",
},
},
Object {
"id": "gpx/4320000000000000/2trk/000000/000000",
"key": "gpx/4320000000000000/2trk/000000/000000",
"id": "gpx/4320000000000000/3trk/000000/000000",
"key": "gpx/4320000000000000/3trk/000000/000000",
"value": Object {
"rev": "1-9ecf6e716dbbb26576a0b13a062b8f5f",
"rev": "1-68d7de0569de570229ea9f9e1a0b13cb",
},
},
],
@ -155,24 +155,24 @@ Object {
},
},
Object {
"id": "gpx/4320000000000000/2trk/000000",
"key": "gpx/4320000000000000/2trk/000000",
"id": "gpx/4320000000000000/3trk/000000",
"key": "gpx/4320000000000000/3trk/000000",
"value": Object {
"rev": "1-46d2f0dcad2299e6ba2830cb1e10b234",
"rev": "1-4c114f3ae0073151e4082ff1d220c2a4",
},
},
Object {
"id": "gpx/4320000000000000/2trk/000000/000000",
"key": "gpx/4320000000000000/2trk/000000/000000",
"id": "gpx/4320000000000000/3trk/000000/000000",
"key": "gpx/4320000000000000/3trk/000000/000000",
"value": Object {
"rev": "1-9ecf6e716dbbb26576a0b13a062b8f5f",
"rev": "1-68d7de0569de570229ea9f9e1a0b13cb",
},
},
Object {
"id": "gpx/4320000000000000/2trk/000000/000000/000000",
"key": "gpx/4320000000000000/2trk/000000/000000/000000",
"id": "gpx/4320000000000000/3trk/000000/000000/000000",
"key": "gpx/4320000000000000/3trk/000000/000000/000000",
"value": Object {
"rev": "1-99c4c054903f577d66ddac0384e04d06",
"rev": "1-7d917d1f3505fe0e3092161694904b53",
},
},
],
@ -196,10 +196,10 @@ Object {
},
},
Object {
"id": "gpx/4320000000000000/0wpt/000000",
"key": "gpx/4320000000000000/0wpt/000000",
"id": "gpx/4320000000000000/1wpt/000000",
"key": "gpx/4320000000000000/1wpt/000000",
"value": Object {
"rev": "1-a3213e8257fb142c09f8b7d7c9482dac",
"rev": "1-c6793365fd0dd56236ab8734a41c7ae7",
},
},
],
@ -223,10 +223,10 @@ Object {
},
},
Object {
"id": "gpx/4320000000000000/1rte/000000",
"key": "gpx/4320000000000000/1rte/000000",
"id": "gpx/4320000000000000/2rte/000000",
"key": "gpx/4320000000000000/2rte/000000",
"value": Object {
"rev": "1-a683896687f08ed73ceede02dc0c210e",
"rev": "1-2ca14f512a9c83f5a239389e580befce",
},
},
],
@ -250,17 +250,17 @@ Object {
},
},
Object {
"id": "gpx/4320000000000000/1rte/000000",
"key": "gpx/4320000000000000/1rte/000000",
"id": "gpx/4320000000000000/2rte/000000",
"key": "gpx/4320000000000000/2rte/000000",
"value": Object {
"rev": "1-a683896687f08ed73ceede02dc0c210e",
"rev": "1-2ca14f512a9c83f5a239389e580befce",
},
},
Object {
"id": "gpx/4320000000000000/1rte/000000/000000",
"key": "gpx/4320000000000000/1rte/000000/000000",
"id": "gpx/4320000000000000/2rte/000000/000000",
"key": "gpx/4320000000000000/2rte/000000/000000",
"value": Object {
"rev": "1-e2eff2ff270417d00f681fcc3f7ceafe",
"rev": "1-0f4064d20f6bfac3888a7758851fbac5",
},
},
],

View File

@ -20,7 +20,7 @@ describe('The rte module', () => {
test('db.put() a new rte when required', async () => {
putNewRte({ gpx: 4320000000000000, rte: 25 });
await expect(globalThis.db.put).toBeCalledWith({
_id: 'gpx/4320000000000000/1rte/000025',
_id: 'gpx/4320000000000000/2rte/000025',
_rev: undefined,
doc: {
cmt: undefined,

View File

@ -20,7 +20,7 @@ describe('The rtept module', () => {
test('db.put() a new rtept when required', async () => {
putNewRtept({ gpx: 0, rte: 0, rtept: 0 });
await expect(globalThis.db.put).toBeCalledWith({
_id: 'gpx/0000000000000000/1rte/000000/000000',
_id: 'gpx/0000000000000000/2rte/000000/000000',
_rev: undefined,
doc: {
$: { lat: 0, lon: 0 },

View File

@ -20,7 +20,7 @@ describe('The trk module', () => {
test('db.put() a new trk when required', async () => {
putNewTrk({ gpx: 1, trk: 2 });
await expect(globalThis.db.put).toBeCalledWith({
_id: 'gpx/0000000000000001/2trk/000002',
_id: 'gpx/0000000000000001/3trk/000002',
_rev: undefined,
doc: {
cmt: undefined,

View File

@ -25,7 +25,7 @@ describe('The trkpt module', () => {
trkpt: 4,
});
await expect(globalThis.db.put).toBeCalledWith({
_id: 'gpx/0000000000000001/2trk/000002/000003/000004',
_id: 'gpx/0000000000000001/3trk/000002/000003/000004',
_rev: undefined,
doc: {
$: { lat: 0, lon: 0 },

View File

@ -20,7 +20,7 @@ describe('The trkseg module', () => {
test('db.put() a new trk when required', async () => {
putNewTrkseg({ gpx: 1234567890123456, trk: 123456, trkseg: 5 });
await expect(globalThis.db.put).toBeCalledWith({
_id: 'gpx/1234567890123456/2trk/123456/000005',
_id: 'gpx/1234567890123456/3trk/123456/000005',
_rev: undefined,
doc: {
trkpt: undefined,

50
src/db/types.d.ts vendored
View File

@ -1,8 +1,8 @@
interface Gpx {
$: Gpx_;
metadata?: Metadata;
wpt?: any[];
rte?: any[];
wpt?: Wpt[];
rte?: Rte[];
trk?: Trk[];
extensions?: Extensions;
}
@ -27,10 +27,21 @@ interface Metadata {
link?: Link[];
time?: string;
keywords?: string;
bounds?: string;
bounds?: Bounds;
extensions?: Extensions;
}
interface Bounds {
$: Bounds_;
}
interface Bounds_ {
minlat: number;
minlon: number;
maxlat: number;
maxlon: number;
}
interface Extensions {
'dyo:speed'?: number;
'dyo:course'?: number;
@ -67,7 +78,7 @@ interface Trkseg {
}
interface Wpt {
$: Trkpt_;
$: Wpt_;
ele?: number;
time?: string;
magvar?: number;
@ -89,7 +100,7 @@ interface Wpt {
extensions?: Extensions;
}
interface Trkpt_ {
interface Wpt_ {
lat: number;
lon: number;
}
@ -103,33 +114,6 @@ interface Rte {
number?: number;
type?: string;
extensions?: Extensions;
rtept?: Rtept[];
rtept?: Wpt[];
}
interface Rtept {
$: Rtept_;
ele?: number;
time?: string;
magvar?: number;
geoidheight?: number;
name?: string;
cmt?: string;
desc?: string;
src?: string;
link?: Link;
sym?: string;
type?: string;
fix?: string;
sat?: number;
hdop?: number;
vdop?: number;
pdop?: number;
ageofdgpsdata?: number;
dgpsid?: number;
extensions?: Extensions;
}
interface Rtept_ {
lat: number;
lon: number;
}

View File

@ -20,7 +20,7 @@ describe('The wpt module', () => {
test('db.put() a new wpt when required', async () => {
putNewWpt({ gpx: 1, wpt: 2 });
await expect(globalThis.db.put).toBeCalledWith({
_id: 'gpx/0000000000000001/0wpt/000002',
_id: 'gpx/0000000000000001/1wpt/000002',
_rev: undefined,
doc: {
$: { lat: 0, lon: 0 },

View File

@ -14,30 +14,30 @@ describe('Checking some DocURI features', () => {
describe('Checking a multilevel route', () => {
test(', using the two levels', () => {
const gpx = route('gpx/:gpx/2trk/:trk');
expect(gpx({ gpx: 10, trk: 0 })).toBe('gpx/10/2trk/0');
const gpx = route('gpx/:gpx/3trk/:trk');
expect(gpx({ gpx: 10, trk: 0 })).toBe('gpx/10/3trk/0');
});
test(', using the two levels (vive-versa)', () => {
const gpx = route('gpx/:gpx/2trk/:trk');
expect(gpx('gpx/10/2trk/0')).toMatchObject({ gpx: '10', trk: '0' });
const gpx = route('gpx/:gpx/3trk/:trk');
expect(gpx('gpx/10/3trk/0')).toMatchObject({ gpx: '10', trk: '0' });
});
});
describe('Checking a multilevel route with optional part', () => {
test(', using the two levels', () => {
const gpx = route('gpx/:gpx(/2trk/:trk)');
expect(gpx({ gpx: 10, trk: 0 })).toBe('gpx/10/2trk/0');
const gpx = route('gpx/:gpx(/3trk/:trk)');
expect(gpx({ gpx: 10, trk: 0 })).toBe('gpx/10/3trk/0');
});
test(', using the two levels (vive-versa)', () => {
const gpx = route('gpx/:gpx(/2trk/:trk)');
expect(gpx('gpx/10/2trk/0')).toMatchObject({ gpx: '10', trk: '0' });
const gpx = route('gpx/:gpx(/3trk/:trk)');
expect(gpx('gpx/10/3trk/0')).toMatchObject({ gpx: '10', trk: '0' });
});
test(', using only one level', () => {
const gpx = route('gpx/:gpx(/2trk/:trk)');
expect(gpx({ gpx: 10 })).toBe('gpx/10/2trk/'); //Unfortunately !
const gpx = route('gpx/:gpx(/3trk/:trk)');
expect(gpx({ gpx: 10 })).toBe('gpx/10/3trk/'); //Unfortunately !
});
test(', using only one level (vive-versa)', () => {
const gpx = route('gpx/:gpx(/2trk/:trk)');
const gpx = route('gpx/:gpx(/3trk/:trk)');
expect(gpx('gpx/10')).toMatchObject({ gpx: '10' });
});
});
@ -62,7 +62,7 @@ describe('Checking trk ids', () => {
gpx: 1234567890123456,
trk: 123456,
};
const key = 'gpx/1234567890123456/2trk/123456';
const key = 'gpx/1234567890123456/3trk/123456';
test(', vice', () => {
const rte = uri('trk', id);
expect(rte).toBe(key);
@ -79,7 +79,7 @@ describe('Checking trkseg ids', () => {
trk: 0,
trkseg: 3,
};
const key = 'gpx/0000000000000111/2trk/000000/000003';
const key = 'gpx/0000000000000111/3trk/000000/000003';
test(', vice', () => {
const rte = uri('trkseg', id);
expect(rte).toBe(key);
@ -97,7 +97,7 @@ describe('Checking trkpt ids', () => {
trkseg: 0,
trkpt: 155,
};
const key = 'gpx/0000000000000025/2trk/000008/000000/000155';
const key = 'gpx/0000000000000025/3trk/000008/000000/000155';
test(', vice', () => {
const rte = uri('trkpt', id);
expect(rte).toBe(key);

View File

@ -28,12 +28,13 @@ const routes = {
dbdef: route('dbdef', coding),
settings: route('settings', coding),
gpx: route('gpx/:gpx', coding),
wpt: route('gpx/:gpx/0wpt/:wpt', coding),
rte: route('gpx/:gpx/1rte/:rte', coding),
rtept: route('gpx/:gpx/1rte/:rte/:rtept', coding),
trk: route('gpx/:gpx/2trk/:trk', coding),
trkseg: route('gpx/:gpx/2trk/:trk/:trkseg', coding),
trkpt: route('gpx/:gpx/2trk/:trk/:trkseg/:trkpt', coding),
tech: route('gpx/:gpx/0tech', coding),
wpt: route('gpx/:gpx/1wpt/:wpt', coding),
rte: route('gpx/:gpx/2rte/:rte', coding),
rtept: route('gpx/:gpx/2rte/:rte/:rtept', coding),
trk: route('gpx/:gpx/3trk/:trk', coding),
trkseg: route('gpx/:gpx/3trk/:trk/:trkseg', coding),
trkpt: route('gpx/:gpx/3trk/:trk/:trkseg/:trkpt', coding),
};
type RouteKey = keyof typeof routes;